Skip to content

Commit 9732878

Browse files
just-borisfeiqitian
authored andcommitted
load setupTests file at setupTestFramework stage (facebook#846)
fixes facebook#824
1 parent 0c59b59 commit 9732878

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/react-scripts/utils/createJestConfig.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ const pathExists = require('path-exists');
1313
const paths = require('../config/paths');
1414

1515
module.exports = (resolve, rootDir, isEjecting) => {
16-
const setupFiles = [resolve('config/polyfills.js')];
17-
if (pathExists.sync(paths.testsSetup)) {
18-
// Use this instead of `paths.testsSetup` to avoid putting
19-
// an absolute filename into configuration after ejecting.
20-
setupFiles.push('<rootDir>/src/setupTests.js');
21-
}
16+
// Use this instead of `paths.testsSetup` to avoid putting
17+
// an absolute filename into configuration after ejecting.
18+
const setupTestsFile = pathExists.sync(paths.testsSetup) ? '<rootDir>/src/setupTests.js' : undefined;
2219

2320
const config = {
2421
moduleFileExtensions: ['jsx', 'js', 'json'],
2522
moduleNameMapper: {
2623
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': resolve('config/jest/FileStub.js'),
2724
'^.+\\.css$': resolve('config/jest/CSSStub.js')
2825
},
29-
setupFiles: setupFiles,
26+
setupFiles: [resolve('config/polyfills.js')],
27+
setupTestFrameworkScriptFile: setupTestsFile,
3028
testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
3129
testEnvironment: 'node',
3230
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$',

0 commit comments

Comments
 (0)