Skip to content

Commit

Permalink
Load modules from node_modules before custom paths (#5403)
Browse files Browse the repository at this point in the history
* Load modules from node_modules before custom paths

* Update CHANGELOG

* Update CHANGELOG
  • Loading branch information
vlasy authored and cpojer committed Jan 27, 2018
1 parent 0816692 commit 0110101
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
([#5364](https://github.com/facebook/jest/pull/5364))
* `[docs]` Add tutorial page for ES6 class mocks.
([#5383]https://github.com/facebook/jest/pull/5383))
* `[jest-resolve]` Search required modules in node_modules and then in custom
paths.
([#5403](https://github.com/facebook/jest/pull/5403))

## jest 22.1.4

Expand Down Expand Up @@ -1490,4 +1493,4 @@ See https://facebook.github.io/jest/blog/2016/12/15/2016-in-jest.html

## <=0.4.0

* See commit history for changes in previous versions of jest.
* See commit history for changes in previous versions of jest.
9 changes: 9 additions & 0 deletions packages/jest-resolve/src/__tests__/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const path = require('path');
const ModuleMap = require('jest-haste-map').ModuleMap;
const Resolver = require('../');
const userResolver = require('../__mocks__/userResolver');
const nodeModulesPaths = require('../node_modules_paths').default;

beforeEach(() => {
userResolver.mockClear();
Expand Down Expand Up @@ -181,3 +182,11 @@ describe('getMockModule', () => {
);
});
});

describe('nodeModulesPaths', () => {
it('provides custom module paths after node_modules', () => {
const src = require.resolve('../');
const result = nodeModulesPaths(src, {paths: ['./customFolder']});
expect(result[result.length - 1]).toBe('./customFolder');
});
});
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/node_modules_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ export default function nodeModulesPaths(
);
}, []);

return options.paths ? options.paths.concat(dirs) : dirs;
return options.paths ? dirs.concat(options.paths) : dirs;
}

0 comments on commit 0110101

Please sign in to comment.