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

Fix options.moduleNameMapper override order with preset (#3565) #3689

Merged
merged 4 commits into from
Jun 27, 2017
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
28 changes: 27 additions & 1 deletion packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,40 @@ describe('preset', () => {
{},
);

expect(options.moduleNameMapper).toEqual([['b', 'b'], ['a', 'a']]);
expect(options.moduleNameMapper).toEqual([['a', 'a'], ['b', 'b']]);
expect(options.modulePathIgnorePatterns).toEqual(['b', 'a']);
expect(options.setupFiles.sort()).toEqual([
'/node_modules/a',
'/node_modules/b',
'/node_modules/regenerator-runtime/runtime',
]);
});

test('merges with options and moduleNameMapper preset is overridden by options', () => {
// Object initializer not used for properties as a workaround for
// sort-keys eslint rule while specifing properties in
// non-alphabetical order for a better test
const moduleNameMapper = {};
moduleNameMapper.e = 'ee';
moduleNameMapper.b = 'bb';
moduleNameMapper.c = 'cc';
moduleNameMapper.a = 'aa';
const {options} = normalize(
{
moduleNameMapper,
preset: 'react-native',
rootDir: '/root/path/foo',
},
{},
);

expect(options.moduleNameMapper).toEqual([
['e', 'ee'],
['b', 'bb'],
['c', 'cc'],
['a', 'aa'],
]);
});
});

describe('preset without setupFiles', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const setupPreset = (
if (options.moduleNameMapper && preset.moduleNameMapper) {
options.moduleNameMapper = Object.assign(
{},
options.moduleNameMapper,
preset.moduleNameMapper,
options.moduleNameMapper,
);
Expand Down