Skip to content

Commit

Permalink
Fix options.moduleNameMapper override order with preset (jestjs#3565)
Browse files Browse the repository at this point in the history
Adjusted the order so that the options mappings are checked first and then the preset mappings are checked.
The preset mappings can be overridden by the options mappings.
  • Loading branch information
Mark.Whitfeld committed Jun 27, 2017
1 parent 88e2ee8 commit fd5047b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 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,32 @@ 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', () => {
const {options} = normalize(
{
moduleNameMapper: { e: 'ee', c: 'cc', b: 'bb', a: 'aa' },
preset: 'react-native',
rootDir: '/root/path/foo',
},
{},
);

expect(options.moduleNameMapper).toEqual([
['e', 'ee'],
['c', 'cc'],
['b', 'bb'],
['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

0 comments on commit fd5047b

Please sign in to comment.