-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
jest.config.ts
82 lines (78 loc) · 2.82 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import path from 'path';
import Jest from '@jest/types';
interface IJestConfig extends Jest.Config.InitialOptions {
[key: string]: any;
}
export default (resolve: Function, rootDir: string) => {
const conf: IJestConfig = {
rootDir: rootDir,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
testMatch: ['<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
testEnvironment: 'jsdom',
testRunner: require.resolve('jest-circus/runner'),
transform: {
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': resolve('lib/jest/babelTransform.js'),
'^.+\\.css$': resolve('lib/jest/cssTransform.js'),
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': resolve('lib/jest/fileTransform.js'),
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
'^.+\\.module\\.(css|less|styl|sass|scss)$',
],
moduleNameMapper: {
'^react-native$': 'react-native-web',
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
},
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
resetMocks: true,
};
const overrides: IJestConfig = Object.assign({}, require(path.join(rootDir, 'package.json')).jest);
if (overrides) {
const supportedKeys: string[] = [
'clearMocks',
'collectCoverageFrom',
'coveragePathIgnorePatterns',
'coverageReporters',
'coverageThreshold',
'displayName',
'extraGlobals',
'globalSetup',
'globalTeardown',
'moduleNameMapper',
'resetMocks',
'resetModules',
'restoreMocks',
'snapshotSerializers',
'testMatch',
'transform',
'transformIgnorePatterns',
'watchPathIgnorePatterns',
];
supportedKeys.forEach((key: string) => {
if (overrides.hasOwnProperty(key)) {
if (Array.isArray(conf[key]) || typeof conf[key] !== 'object') {
// for arrays or primitive types, directly override the config key
conf[key] = overrides[key];
} else {
// for object types, extend gracefully
conf[key] = Object.assign({}, conf[key], overrides[key]);
}
delete overrides[key];
}
});
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
console.error(
'\x1b[1;31mOut of the box, TSBB only supports overriding \x1b[0m' +
'\x1b[1;31mthese Jest options:\x1b[0m\n\n' +
supportedKeys.map((key) => ' \u2022 ' + key).join('\n') +
'.\n\n' +
'\x1b[1;31mThese options in your package.json Jest configuration \x1b[0m' +
'\x1b[1;31mare not currently supported by TSBB App:\x1b[0m\n\n' +
unsupportedKeys.map((key) => ' \u2022 ' + key).join('\n'),
);
process.exit(1);
}
}
return conf;
};