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

Load modules from node_modules before custom paths #5403

Merged
merged 4 commits into from
Jan 27, 2018
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
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;
}