-
Notifications
You must be signed in to change notification settings - Fork 96
/
jest.config.ts
64 lines (56 loc) · 1.91 KB
/
jest.config.ts
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
// eslint-disable-next-line import/no-import-module-exports
import type { Config } from 'jest';
declare global {
interface ProcessEnv {
REACT_MAJOR_VERSION: string;
CI?: boolean;
}
}
const reactMajorVersion = process.env.REACT_MAJOR_VERSION;
const config: Config = {
clearMocks: true,
modulePathIgnorePatterns: ['/dist/'],
resetMocks: true,
resetModules: true,
restoreMocks: true,
// We need a `snapshotResolver` because we run our tests
// for different react versions. Each version render components
// differently thus returning a different snapshot. We'll store
// each snapshot in different folders:
// __react_16_snapshots__, __react_17_snapshots__, etc.
snapshotResolver: '<rootDir>/test/setup/snapshot-resolver.ts',
setupFiles: ['./test/setup/env-setup.ts'],
setupFilesAfterEnv: ['./test/setup/test-setup.ts'],
testEnvironment: './test/setup/environment.ts',
// node_modules is default.
testPathIgnorePatterns: ['/node_modules/', '/cypress/'],
transform: {
'\\.[jt]sx?$': 'babel-jest',
},
verbose: true,
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
};
// eslint-disable-next-line no-console
console.log('Testing with React version:', `${reactMajorVersion || '18'}.x.x`);
if (['16', '17'].includes(reactMajorVersion)) {
config.testPathIgnorePatterns = [
...(config.testPathIgnorePatterns || []),
// These test do not requires react and will
// be run in the base run (with react v18)
'test/unit/docs',
'test/unit/health',
];
config.cacheDirectory = `.cache/jest-cache-react-${reactMajorVersion}`;
config.moduleNameMapper = {
'^@testing-library/react((\\/.*)?)$': `@testing-library/react-16-17$1`,
'^react-dom((\\/.*)?)$': `react-dom-${reactMajorVersion}$1`,
'^react((\\/.*)?)$': `react-${reactMajorVersion}$1`,
};
}
if (process.env.CI) {
config.maxWorkers = 2;
}
module.exports = config;