Skip to content

Commit

Permalink
First setup presets before options validation (jestjs#7724)
Browse files Browse the repository at this point in the history
  • Loading branch information
doniyor2109 authored and captain-yossarian committed Jul 18, 2019
1 parent 5dee35e commit 29b1e1c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ describe('preset', () => {
moduleNameMapper: {b: 'b'},
modulePathIgnorePatterns: ['b'],
setupFiles: ['b'],
setupFilesAfterEnv: ['b'],
transform: {b: 'b'},
}),
{virtual: true},
Expand Down Expand Up @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
Expand All @@ -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,
Expand Down

0 comments on commit 29b1e1c

Please sign in to comment.