From ac48b51175d4f30b511231f800f67dc36758b4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20H=C3=A4kkinen?= Date: Thu, 12 Sep 2024 09:46:14 +0300 Subject: [PATCH 1/3] Test database migrations in CI --- .github/workflows/run-tests.yaml | 19 +++++++++++++++++++ compose.yaml | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index ffd3d3f..52f1f06 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -34,3 +34,22 @@ jobs: run: npm ci - name: Run prettier run: npm run format:check + + migrations: + name: Check database migrations + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - name: Build Docker image + run: npm run build + - name: Start Postgres + run: docker compose up -d db + - name: Run migrations + run: docker compose run app npm run migration:run + - name: Stop Postgres + run: npm stop diff --git a/compose.yaml b/compose.yaml index 4918cce..45e9cb8 100644 --- a/compose.yaml +++ b/compose.yaml @@ -7,7 +7,8 @@ services: context: app dockerfile: Dockerfile.dev env_file: - - .env + - path: .env + required: false environment: NODE_ENV: development DATABASE_NAME: kaiku_dev From 73f9d3a0317365ebe5aff441647758eb4ba0e0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20H=C3=A4kkinen?= Date: Thu, 12 Sep 2024 10:14:27 +0300 Subject: [PATCH 2/3] Add test scripts --- .prettierignore | 1 + package.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..be0b8b3 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +app/dist diff --git a/package.json b/package.json index 220a8fe..09b755c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "build": "docker compose build", "logs": "docker compose logs -f app", "postinstall": "cd app && npm ci", - "format:check": "prettier --check ." + "format:check": "prettier --check .", + "lint": "cd app && npm run lint", + "test": "npm run format:check && npm run lint" }, "author": "Joonas Häkkinen ", "license": "GPL-3.0", From 730a9cca78c16e4406d40d85fe61420311e097a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20H=C3=A4kkinen?= Date: Thu, 12 Sep 2024 10:19:39 +0300 Subject: [PATCH 3/3] Update docs --- README.md | 1 + docs/testing.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 docs/testing.md diff --git a/README.md b/README.md index f732897..089b15a 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,4 @@ revolves around easily sharing information about when and where from you are wor - [Requirements](./docs/requirements.md) - [Configuration](./docs/configuration.md) +- [Testing](./docs/testing.md) diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..5998327 --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,32 @@ +# Testing + +Currently, Kaiku's test suite includes only linting, formatting, and database migration checks. The +plan is to utilize integration tests as the primary tool once the project matures slightly more. + +Passing all tests is required for code to be merged into `main`. + +## Local Development + +Run all local tests with `npm test`. (Does not include migration tests.) + +### Linting + +Linting is configured only for the `app/` folder and uses ESLint. + +```bash +npm run lint +``` + +### Formatting + +Prettier is used to format all code in the repository. The formatting test passes if formatting +results in an empty diff. Prettier is configured in repository root. + +```bash +npm run format:check +``` + +## CI/CD + +GitHub Actions is used for CI/CD. In addition to linting and formatting, also database migrations +are run on CI. This test simply requires the migration run to result in the zero exit code.