From 399a64abe51d349766dd4edffefef2ae9cde94ea 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 --- 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 | 25 +++++++++++++++++++ packages/next-drupal/jest.setup.ts | 1 + packages/next-drupal/package.json | 2 +- 8 files changed, 53 insertions(+), 26 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/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 2beab210..e5bb8405 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 a3568ca2..d1fd2984 100644 --- a/packages/next-drupal-query/package.json +++ b/packages/next-drupal-query/package.json @@ -19,7 +19,7 @@ "scripts": { "prepare": "microbundle --no-compress --jsx React.createElement --format modern,cjs", "dev": "microbundle watch --no-compress --jsx React.createElement --format modern,cjs", - "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..e747281a --- /dev/null +++ b/packages/next-drupal/jest.config.cjs @@ -0,0 +1,25 @@ +/** @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: { + statements: 58.91, + branches: 74.61, + functions: 77.77, + lines: 58.91, + }, + }, +} 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 ad0b87ba..b28852f9 100644 --- a/packages/next-drupal/package.json +++ b/packages/next-drupal/package.json @@ -19,7 +19,7 @@ "scripts": { "prepare": "microbundle --no-compress --jsx React.createElement --format modern,cjs", "dev": "microbundle watch --no-compress --jsx React.createElement --format modern,cjs", - "test": "jest" + "test": "jest --verbose" }, "keywords": [ "next.js",