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
…jestjs#3689)

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

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.

* Fix prettier linting issues

* Fix eslint issues

* Workaround in test for eslint sort-keys rule
  • Loading branch information
markwhitfeld authored and cpojer committed Jun 27, 2017
1 parent 6d70d6a commit 37873e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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

0 comments on commit 37873e1

Please sign in to comment.