Skip to content

Commit 73a0a91

Browse files
committed
create distinct frontend and api test environments
Signed-off-by: Gerhard Steenkamp <[email protected]>
1 parent e2d07e4 commit 73a0a91

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

jest.config.cjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ module.exports = {
1111
"^.+\\.svg$": "jest-transform-stub",
1212
"^.+\\.png$": "jest-transform-stub",
1313
},
14+
// Only include test/api directory for API tests
15+
testMatch: ["<rootDir>/test/api/**/*.test.{ts,tsx}"],
1416
moduleNameMapper: {
15-
"^components/(.*)$": "<rootDir>/src/components/$1",
16-
"^utils/(.*)$": "<rootDir>/src/utils/$1",
17-
"^hooks/(.*)$": "<rootDir>/src/hooks/$1",
18-
"^assets/(.*)$": "<rootDir>/src/assets/$1",
19-
"^data/(.*)$": "<rootDir>/src/data/$1",
17+
// Only keep uuid mapping for API tests - remove frontend path mappings
2018
uuid: require.resolve("uuid"),
2119
},
2220
};

jest.frontend.config.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
2+
3+
module.exports = {
4+
setupFiles: ["<rootDir>/setup.jest.ts"],
5+
preset: "ts-jest",
6+
testEnvironment: "jsdom",
7+
moduleDirectories: ["node_modules", "<rootDir>"],
8+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
9+
transform: {
10+
"^.+\\.tsx?$": "ts-jest",
11+
"^.+\\.svg$": "jest-transform-stub",
12+
"^.+\\.png$": "jest-transform-stub",
13+
},
14+
// Only include src directory for frontend tests
15+
testMatch: ["<rootDir>/src/**/*.test.{ts,tsx}"],
16+
// Exclude API modules that require Node.js dependencies
17+
modulePathIgnorePatterns: ["<rootDir>/api/", "<rootDir>/test/api/"],
18+
moduleNameMapper: {
19+
"^components/(.*)$": "<rootDir>/src/components/$1",
20+
"^utils/(.*)$": "<rootDir>/src/utils/$1",
21+
"^hooks/(.*)$": "<rootDir>/src/hooks/$1",
22+
"^assets/(.*)$": "<rootDir>/src/assets/$1",
23+
"^data/(.*)$": "<rootDir>/src/data/$1",
24+
uuid: require.resolve("uuid"),
25+
},
26+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
"remote-config": "tsx scripts/fetch-remote-config.ts",
7070
"remote-env": "tsx ./scripts/fetch-remote-env.ts",
7171
"analyze": "yarn build && rollup-plugin-visualizer --open ./bundle-size-analysis.json",
72-
"test": "export REACT_APP_GIT_COMMIT_HASH=$(git rev-parse HEAD) && jest --env jsdom src",
72+
"test": "export REACT_APP_GIT_COMMIT_HASH=$(git rev-parse HEAD) && jest --config jest.frontend.config.cjs",
7373
"serve": "vite preview --port 3000",
74-
"test-api": "yarn remote-config && jest test/api",
74+
"test-api": "yarn remote-config && jest --config jest.config.cjs",
7575
"pretest:e2e": "npm pkg set 'type'='module'",
7676
"test:e2e:headful": "yarn pretest:e2e && playwright test",
7777
"test:e2e:headless": "yarn pretest:e2e && HEADLESS=true playwright test",

0 commit comments

Comments
 (0)