-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.config.cjs
More file actions
74 lines (66 loc) · 2.21 KB
/
Copy pathjest.config.cjs
File metadata and controls
74 lines (66 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Jest is configured in CommonJS mode (not ESM) for stability:
*
* The project's runtime uses `"type": "module"` + `module: nodenext`, but Jest's ESM
* support has known interop issues with CJS deps that export named bindings (notably
* `casper-js-sdk`, which ships CJS via `dist/lib.node.js`). Forcing ts-jest to emit
* CommonJS for tests sidesteps that entirely while still type-checking the same way
* production builds expect.
*
* The `moduleNameMapper` strip is what makes nodenext-style `'./foo.js'` imports
* (which point at `.ts` files) work under Jest.
*
* @type {import('jest').Config}
*/
const config = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
// uuid v14+ is ESM-only; redirect to a CJS stub for Jest.
'^uuid$': '<rootDir>/src/__test-utils__/uuid-mock.cjs',
// nodenext-style `./foo.js` imports point at `.ts` source; strip the suffix.
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
// Also transform `.mjs`/`.js` files from whitelisted ESM-only deps (see
// `transformIgnorePatterns`). ts-jest accepts JS when `allowJs: true`.
'^.+\\.(t|m?j)sx?$': [
'ts-jest',
{
useESM: false,
tsconfig: {
module: 'commonjs',
moduleResolution: 'node',
target: 'esnext',
esModuleInterop: true,
allowSyntheticDefaultImports: true,
allowJs: true,
strict: false,
skipLibCheck: true,
isolatedModules: true,
types: ['node', 'jest'],
},
},
],
},
moduleFileExtensions: ['ts', 'tsx', 'mjs', 'js', 'jsx', 'json'],
// Whitelist ESM-only transitive deps that need transforming.
transformIgnorePatterns: ['node_modules/(?!(@noble|@scure|nanoid|jose|ws|@bufbuild)/)'],
testMatch: ['<rootDir>/src/**/*.test.ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/index.ts',
'!src/typings/**',
'!src/__fixtures__/**',
'!src/__test-utils__/**',
'!src/domain/**/repository.ts',
'!src/domain/**/entities.ts',
],
coverageDirectory: 'coverage',
coverageReporters: ['text-summary', 'lcov', 'html'],
clearMocks: true,
restoreMocks: true,
};
module.exports = config;