Skip to content

Commit 0110101

Browse files
vlasycpojer
authored andcommitted
Load modules from node_modules before custom paths (#5403)
* Load modules from node_modules before custom paths * Update CHANGELOG * Update CHANGELOG
1 parent 0816692 commit 0110101

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
([#5364](https://github.com/facebook/jest/pull/5364))
1818
* `[docs]` Add tutorial page for ES6 class mocks.
1919
([#5383]https://github.com/facebook/jest/pull/5383))
20+
* `[jest-resolve]` Search required modules in node_modules and then in custom
21+
paths.
22+
([#5403](https://github.com/facebook/jest/pull/5403))
2023

2124
## jest 22.1.4
2225

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

14911494
## <=0.4.0
14921495

1493-
* See commit history for changes in previous versions of jest.
1496+
* See commit history for changes in previous versions of jest.

packages/jest-resolve/src/__tests__/resolve.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const path = require('path');
1515
const ModuleMap = require('jest-haste-map').ModuleMap;
1616
const Resolver = require('../');
1717
const userResolver = require('../__mocks__/userResolver');
18+
const nodeModulesPaths = require('../node_modules_paths').default;
1819

1920
beforeEach(() => {
2021
userResolver.mockClear();
@@ -181,3 +182,11 @@ describe('getMockModule', () => {
181182
);
182183
});
183184
});
185+
186+
describe('nodeModulesPaths', () => {
187+
it('provides custom module paths after node_modules', () => {
188+
const src = require.resolve('../');
189+
const result = nodeModulesPaths(src, {paths: ['./customFolder']});
190+
expect(result[result.length - 1]).toBe('./customFolder');
191+
});
192+
});

packages/jest-resolve/src/node_modules_paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ export default function nodeModulesPaths(
5252
);
5353
}, []);
5454

55-
return options.paths ? options.paths.concat(dirs) : dirs;
55+
return options.paths ? dirs.concat(options.paths) : dirs;
5656
}

0 commit comments

Comments
 (0)