Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First setup presets before options validation #7724

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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