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

Treat setupFilesAfterEnv like setupFiles when normalizing configs against presets #9495

Merged
merged 2 commits into from Feb 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

### Fixes

- `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495))
- `[jest-snapshot]` Downgrade semver to v6 to support node 8 ([#9451](https://github.com/facebook/jest/pull/9451))
- `[jest-transform]` Correct sourcemap behavior for transformed and instrumented code ([#9460](https://github.com/facebook/jest/pull/9460))
- `[pretty-format]` Export `OldPlugin` type ([#9491](https://github.com/facebook/jest/pull/9491))
Expand Down
78 changes: 43 additions & 35 deletions packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -1137,6 +1137,7 @@ describe('preset', () => {
preset: 'react-native',
rootDir: '/root/path/foo',
setupFiles: ['a'],
setupFilesAfterEnv: ['a'],
transform: {a: 'a'},
},
{},
Expand All @@ -1151,6 +1152,10 @@ describe('preset', () => {
'/node_modules/a',
'/node_modules/b',
]);
expect(options.setupFilesAfterEnv.sort()).toEqual([
'/node_modules/a',
'/node_modules/b',
]);
expect(options.transform).toEqual([
['a', '/node_modules/a', {}],
['b', '/node_modules/b', {}],
Expand Down Expand Up @@ -1278,45 +1283,48 @@ describe('preset with globals', () => {
});
});

describe('preset without setupFiles', () => {
let Resolver;
beforeEach(() => {
Resolver = require('jest-resolve');
Resolver.findNodeModule = jest.fn(
name => path.sep + 'node_modules' + path.sep + name,
);
});
describe.each(['setupFiles', 'setupFilesAfterEnv'])(
'preset without %s',
configKey => {
let Resolver;
beforeEach(() => {
Resolver = require('jest-resolve');
Resolver.findNodeModule = jest.fn(
name => path.sep + 'node_modules' + path.sep + name,
);
});

beforeAll(() => {
jest.doMock(
'/node_modules/react-foo/jest-preset',
() => ({
moduleNameMapper: {b: 'b'},
modulePathIgnorePatterns: ['b'],
}),
{virtual: true},
);
});
beforeAll(() => {
jest.doMock(
'/node_modules/react-foo/jest-preset',
() => ({
moduleNameMapper: {b: 'b'},
modulePathIgnorePatterns: ['b'],
}),
{virtual: true},
);
});

afterAll(() => {
jest.dontMock('/node_modules/react-foo/jest-preset');
});
afterAll(() => {
jest.dontMock('/node_modules/react-foo/jest-preset');
});

it('should normalize setupFiles correctly', () => {
const {options} = normalize(
{
preset: 'react-foo',
rootDir: '/root/path/foo',
setupFiles: ['a'],
},
{},
);
it(`should normalize ${configKey} correctly`, () => {
const {options} = normalize(
{
[configKey]: ['a'],
preset: 'react-foo',
rootDir: '/root/path/foo',
},
{},
);

expect(options).toEqual(
expect.objectContaining({setupFiles: ['/node_modules/a']}),
);
});
});
expect(options).toEqual(
expect.objectContaining({[configKey]: ['/node_modules/a']}),
);
});
},
);

describe('runner', () => {
let Resolver;
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -156,6 +156,11 @@ const setupPreset = (
if (options.setupFiles) {
options.setupFiles = (preset.setupFiles || []).concat(options.setupFiles);
}
if (options.setupFilesAfterEnv) {
options.setupFilesAfterEnv = (preset.setupFilesAfterEnv || []).concat(
options.setupFilesAfterEnv,
);
}
if (options.modulePathIgnorePatterns && preset.modulePathIgnorePatterns) {
options.modulePathIgnorePatterns = preset.modulePathIgnorePatterns.concat(
options.modulePathIgnorePatterns,
Expand Down