diff --git a/CHANGELOG.md b/CHANGELOG.md index 57758e6de245..e6077184f0f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ ### Fixes -- `[jest-cli]` Break dependency cycle when using Jest programmatically ([#7707](https://github.com/facebook/jest/pull/7707) +- `[jest-cli]` Break dependency cycle when using Jest programmatically ([#7707](https://github.com/facebook/jest/pull/7707)) +- `[jest-config]` Extract setupFilesAfterEnv from preset ([#7724](https://github.com/facebook/jest/pull/7724)) ### Chore & Maintenance diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index ffebc661caa9..9090ec672c35 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -926,6 +926,7 @@ describe('preset', () => { moduleNameMapper: {b: 'b'}, modulePathIgnorePatterns: ['b'], setupFiles: ['b'], + setupFilesAfterEnv: ['b'], transform: {b: 'b'}, }), {virtual: true}, @@ -1106,6 +1107,18 @@ describe('preset', () => { ['a', '/node_modules/aa'], ]); }); + + test('extracts setupFilesAfterEnv from preset', () => { + const {options} = normalize( + { + preset: 'react-native', + rootDir: '/root/path/foo', + }, + {}, + ); + + expect(options.setupFilesAfterEnv).toEqual(['/node_modules/b']); + }); }); describe('preset without setupFiles', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index f63714494aca..282315a2bfa1 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -398,6 +398,10 @@ export default function normalize(options: InitialOptions, argv: Argv) { ), ); + if (options.preset) { + options = setupPreset(options, options.preset); + } + if (!options.setupFilesAfterEnv) { options.setupFilesAfterEnv = []; } @@ -420,10 +424,6 @@ export default function normalize(options: InitialOptions, argv: Argv) { options.setupFilesAfterEnv.push(options.setupTestFrameworkScriptFile); } - if (options.preset) { - options = setupPreset(options, options.preset); - } - options.testEnvironment = getTestEnvironment({ rootDir: options.rootDir, testEnvironment: options.testEnvironment || DEFAULT_CONFIG.testEnvironment,