From fd5ce9fc16c1364e4ef41f3ef93da9edd9f8d021 Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Wed, 22 Nov 2023 21:11:57 +0800 Subject: [PATCH] test(next-drupal): add tooling to test code coverage Fixes #609 --- .github/workflows/next-drupal-query.yml | 4 ++- .github/workflows/next-drupal.yml | 2 +- .github/workflows/next.yml | 2 ++ jest.config.ts | 23 ---------------- package.json | 2 +- packages/next-drupal-query/jest.config.cjs | 24 +++++++++++++++++ .../next-drupal-query/jest.setup.ts | 0 packages/next-drupal-query/package.json | 2 +- packages/next-drupal/jest.config.cjs | 26 +++++++++++++++++++ packages/next-drupal/jest.setup.ts | 1 + packages/next-drupal/package.json | 2 +- 11 files changed, 60 insertions(+), 28 deletions(-) delete mode 100644 jest.config.ts create mode 100644 packages/next-drupal-query/jest.config.cjs rename jest.setup.ts => packages/next-drupal-query/jest.setup.ts (100%) create mode 100644 packages/next-drupal/jest.config.cjs create mode 100644 packages/next-drupal/jest.setup.ts diff --git a/.github/workflows/next-drupal-query.yml b/.github/workflows/next-drupal-query.yml index 0e5515c5..00499fbc 100644 --- a/.github/workflows/next-drupal-query.yml +++ b/.github/workflows/next-drupal-query.yml @@ -1,6 +1,8 @@ name: next-drupal-query on: push: + branches: + - main pull_request: types: [opened, synchronize, edited] @@ -12,4 +14,4 @@ jobs: - name: Install modules run: yarn - name: Run tests - run: yarn test packages/next-drupal-query + run: yarn workspace next-drupal-query test diff --git a/.github/workflows/next-drupal.yml b/.github/workflows/next-drupal.yml index 477cd61e..7e2c2d62 100644 --- a/.github/workflows/next-drupal.yml +++ b/.github/workflows/next-drupal.yml @@ -14,7 +14,7 @@ jobs: - name: Install modules run: yarn - name: Run tests - run: yarn test packages/next-drupal + run: yarn workspace next-drupal test env: DRUPAL_BASE_URL: ${{ secrets.DRUPAL_BASE_URL }} DRUPAL_USERNAME: ${{ secrets.DRUPAL_USERNAME }} diff --git a/.github/workflows/next.yml b/.github/workflows/next.yml index 58ddae48..c46b9101 100644 --- a/.github/workflows/next.yml +++ b/.github/workflows/next.yml @@ -1,6 +1,8 @@ name: next on: push: + branches: + - main pull_request: branches: - main diff --git a/jest.config.ts b/jest.config.ts deleted file mode 100644 index 3ab4fbfb..00000000 --- a/jest.config.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { Config } from "@jest/types" - -const config: Config.InitialOptions = { - preset: "ts-jest/presets/js-with-ts", - testEnvironment: "node", - setupFiles: ["dotenv/config"], - setupFilesAfterEnv: ["/jest.setup.ts"], - testMatch: ["**/tests/**/*.test.{ts,tsx}"], - testPathIgnorePatterns: [ - "/node_modules/", - "/fixtures/", - "/dist/", - "/.cache/", - "/drupal/", - ], - globals: { - "ts-jest": { - isolatedModules: true, - }, - }, -} - -export default config diff --git a/package.json b/package.json index a01e639c..07dfe41a 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "sync:starters": "./scripts/sync-starters.sh \"starters/*\"", "seed": "NUM_NODES=200 node ./scripts/seed", "cy:open": "turbo run cy:open --parallel", - "test": "jest", + "test": "yarn workspace next-drupal test && yarn workspace next-drupal-query test", "pretest": "yarn format:check && yarn lint", "test:e2e": "turbo run test:e2e --parallel", "test:e2e:ci": "turbo run test:e2e:ci --parallel" diff --git a/packages/next-drupal-query/jest.config.cjs b/packages/next-drupal-query/jest.config.cjs new file mode 100644 index 00000000..08a1f118 --- /dev/null +++ b/packages/next-drupal-query/jest.config.cjs @@ -0,0 +1,24 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + preset: "ts-jest/presets/js-with-ts", + testEnvironment: "node", + setupFiles: ["dotenv/config"], + setupFilesAfterEnv: ["/jest.setup.ts"], + testMatch: ["**/tests/**/*.test.{ts,tsx}"], + globals: { + "ts-jest": { + isolatedModules: true, + }, + }, + coverageProvider: "v8", + collectCoverage: true, + collectCoverageFrom: ["./src/**"], + coverageThreshold: { + global: { + statements: 85.11, + branches: 58, + functions: 70, + lines: 85.11, + }, + }, +} diff --git a/jest.setup.ts b/packages/next-drupal-query/jest.setup.ts similarity index 100% rename from jest.setup.ts rename to packages/next-drupal-query/jest.setup.ts diff --git a/packages/next-drupal-query/package.json b/packages/next-drupal-query/package.json index 3d08ef64..cf2f4cf6 100644 --- a/packages/next-drupal-query/package.json +++ b/packages/next-drupal-query/package.json @@ -31,7 +31,7 @@ "scripts": { "prepare": "tsup", "dev": "tsup --watch", - "test": "jest" + "test": "jest --verbose" }, "keywords": [ "next.js", diff --git a/packages/next-drupal/jest.config.cjs b/packages/next-drupal/jest.config.cjs new file mode 100644 index 00000000..aef68b77 --- /dev/null +++ b/packages/next-drupal/jest.config.cjs @@ -0,0 +1,26 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + preset: "ts-jest", + testEnvironment: "node", + setupFiles: ["dotenv/config"], + setupFilesAfterEnv: ["/jest.setup.ts"], + testMatch: ["**/tests/**/*.test.{ts,tsx}"], + globals: { + "ts-jest": { + isolatedModules: true, + }, + }, + coverageProvider: "v8", + collectCoverage: true, + collectCoverageFrom: ["./src/**"], + coveragePathIgnorePatterns: ["./src/get-*"], + coverageThreshold: { + global: { + // @TODO Make these thresholds strict once #608 is completed. + statements: 55, // 57.38, + branches: 80, // 83.85, + functions: 75, // 76.36, + lines: 55, // 57.38, + }, + }, +} diff --git a/packages/next-drupal/jest.setup.ts b/packages/next-drupal/jest.setup.ts new file mode 100644 index 00000000..a5ef75aa --- /dev/null +++ b/packages/next-drupal/jest.setup.ts @@ -0,0 +1 @@ +import "isomorphic-fetch" diff --git a/packages/next-drupal/package.json b/packages/next-drupal/package.json index 0efcabe6..40282cd0 100644 --- a/packages/next-drupal/package.json +++ b/packages/next-drupal/package.json @@ -44,7 +44,7 @@ "scripts": { "prepare": "tsup", "dev": "tsup --watch", - "test": "jest" + "test": "jest --verbose" }, "keywords": [ "next.js",