From 593a935af5258e7da174a2f087bbbf824f0db417 Mon Sep 17 00:00:00 2001 From: Fabien 'egg' O'Carroll Date: Tue, 30 Jul 2024 16:25:09 +0700 Subject: [PATCH] Used exec to run tests in existing container The idea here is to simplify and streamline the dev stack. So rather than a separate docker-compose file for testing, and spinning up new containers we can run the tests in the existing activitypub container we use, which also has the local src files mounted. `yarn dev` will start the stack as usual, but now it does it as a daemon, which means it runs in the background. We also pass the --no-recreate flag which ensures that running it multiple times doesn't destroy the container and is essentially idempotent. `yarn stop` will bring the stack down `yarn logs` will tail the activitypub logs for the container `yarn test` uses the `exec` docker compose command to run the tests, and also calls `yarn dev` first - which makes sure the stack is running if it wasn't already. `yarn fix` will remove local containers for activitypub and nginx and then rebuild them --- .github/workflows/build.yml | 3 +-- docker-compose.testing.yml | 31 ------------------------------- package.json | 7 +++++-- 3 files changed, 6 insertions(+), 35 deletions(-) delete mode 100644 docker-compose.testing.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d0d637f..b5c5c00c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,8 +43,7 @@ jobs: image: $IMAGE_NAME:$DOCKER_METADATA_OUTPUT_VERSION" > docker-compose.ci.yml - name: "Run tests" - run: | - docker compose -f docker-compose.testing.yml -f docker-compose.ci.yml up --abort-on-container-exit --exit-code-from activitypub + run: yarn test - name: Login to GAR uses: docker/login-action@v3 diff --git a/docker-compose.testing.yml b/docker-compose.testing.yml deleted file mode 100644 index b99dfcbb..00000000 --- a/docker-compose.testing.yml +++ /dev/null @@ -1,31 +0,0 @@ -services: - activitypub: - build: . - environment: - - MYSQL_USER=ghost - - MYSQL_PASSWORD=password - - MYSQL_HOST=mysql-testing - - MYSQL_PORT=3306 - - MYSQL_DATABASE=activitypub - - NODE_ENV=testing - command: yarn test:all - depends_on: - mysql-testing: - condition: service_healthy - - mysql-testing: - image: mysql:lts - volumes: - - mysql-test-volume:/var/lib/mysql - environment: - - MYSQL_ROOT_PASSWORD=root - - MYSQL_USER=ghost - - MYSQL_PASSWORD=password - - MYSQL_DATABASE=activitypub - healthcheck: - test: "mysql -ughost -ppassword activitypub -e 'select 1'" - interval: 1s - retries: 120 - -volumes: - mysql-test-volume: diff --git a/package.json b/package.json index c85016d4..ff2ffa0b 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,16 @@ "main": "src/app.ts", "type": "module", "scripts": { - "dev": "docker compose up", + "dev": "docker compose up -d --no-recreate", + "stop": "docker compose down", + "fix": "docker compose rm activitypub nginx -sf && docker compose build activitypub nginx", + "logs": "docker compose logs activitypub -f", + "test": "yarn dev && docker compose exec activitypub yarn test:all", "test:types": "tsc --noEmit", "test:unit": "c8 --src src --all --reporter text --reporter cobertura mocha -r tsx './src/**/*.unit.test.ts'", "test:integration": "c8 --src src --all --reporter text --reporter cobertura mocha -r tsx './src/**/*.integration.test.ts'", "test:code": "c8 --src src --all --reporter text --reporter cobertura mocha -r tsx './src/**/*.test.ts'", "test:all": "yarn test:types && yarn test:code", - "test": "docker compose -f docker-compose.testing.yml up --abort-on-container-exit --exit-code-from activitypub", "lint:code": "eslint *.js lib/ --ext .js --cache", "lint": "yarn lint:code" },