/
jest.config.js
91 lines (89 loc) · 2.79 KB
/
jest.config.js
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
83
84
85
86
87
88
89
90
91
const fs = require('fs');
const color = require('colors-cli/safe');
const paths = require('./');
module.exports = (resolve, rootDir) => {
// Use this instead of `paths.testsSetup` to avoid putting
// an absolute filename into configuration after ejecting.
const setupTestsFile = fs.existsSync(paths.testsSetup)
? '<rootDir>/src/setupTests.js'
: undefined;
// TODO: I don't know if it's safe or not to just use / as path separator
// in Jest configs. We need help from somebody with Windows to determine this.
const config = {
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
],
setupTestFrameworkScriptFile: setupTestsFile,
testMatch: [
'<rootDir>/**/__tests__/**/*.{ts,tsx}',
'<rootDir>/**/?(*.)(spec|test).{ts,tsx}',
],
testEnvironment: 'node',
// testEnvironment: 'jsdom',
testURL: 'http://localhost',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': resolve('conf/jest/babelTransform.js'),
'^.+\\.css$': resolve('conf/jest/cssTransform.js'),
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': resolve('conf/jest/fileTransform.js'),
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss|less)$',
],
moduleNameMapper: {
'^react-native$': 'react-native-web',
'^.+\\.module\\.(css|less|sass|scss)$': 'identity-obj-proxy',
},
};
if (rootDir) {
config.rootDir = rootDir;
}
// eslint-disable-next-line
const overrides = Object.assign({}, require(paths.appPackageJson).jest);
const supportedKeys = [
'collectCoverageFrom',
'coverageReporters',
'coverageThreshold',
'globals',
'mapCoverage',
'moduleFileExtensions',
'moduleNameMapper',
'modulePaths',
'snapshotSerializers',
'setupFiles',
'testMatch',
'testEnvironmentOptions',
'testResultsProcessor',
'transform',
'transformIgnorePatterns',
'reporters',
];
if (overrides) {
supportedKeys.forEach((key) => {
// eslint-disable-next-line
if (overrides.hasOwnProperty(key)) {
config[key] = overrides[key];
delete overrides[key];
}
});
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
/* eslint-disable */
console.error(
color.red(
'Out of the box, kkt only supports overriding ' +
'these Jest options:\n\n' +
supportedKeys.map(key => color.bold(' \u2022 ' + key)).join('\n') +
'.\n\n' +
'These options in your package.json Jest configuration ' +
'are not currently supported by kkt:\n\n' +
unsupportedKeys.map(key => color.bold(' \u2022 ' + key)).join('\n')
)
);
/* eslint-enable */
process.exit(1);
}
}
return config;
};