Skip to content

Commit

Permalink
jest-haste-map: Emit change events if a file in node_modules has chan…
Browse files Browse the repository at this point in the history
…ged. (jestjs#2682)
  • Loading branch information
cpojer authored and skovhus committed Apr 29, 2017
1 parent b2a0266 commit 174011c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"modulePathIgnorePatterns": [
"examples/.*",
"packages/.*/build",
"packages/jest-runtime/src/__tests__/test_root_with_dup_mocks"
"packages/jest-runtime/src/__tests__/test_root.*",
"website/.*"
],
"collectCoverageFrom": [
"**/packages/jest-*/**/*.js",
Expand Down
28 changes: 28 additions & 0 deletions packages/jest-haste-map/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ describe('HasteMap', () => {
const statObject = {mtime: {getTime: () => 45}};
const tests = [
() => {
// Tests that the change event works correctly.
mockEmitters['/fruits'].emit(
'all',
'delete',
Expand Down Expand Up @@ -713,6 +714,7 @@ describe('HasteMap', () => {
);
},
() => {
// Ensures the event queue can receive multiple events.
mockFs['/fruits/tomato.js'] = [
'/**',
' * @providesModule Tomato',
Expand Down Expand Up @@ -765,6 +767,7 @@ describe('HasteMap', () => {
);
},
() => {
// Does not emit duplicate change events.
mockEmitters['/fruits'].emit(
'all',
'change',
Expand All @@ -787,6 +790,31 @@ describe('HasteMap', () => {
}),
);
},
() => {
// Emits a change even if a file in node_modules has changed.
mockEmitters['/fruits'].emit(
'all',
'add',
'apple.js',
'/fruits/node_modules/',
statObject,
);
hasteMap.once(
'change',
addErrorHandler(({eventsQueue, hasteFS, moduleMap}) => {
const filePath = '/fruits/node_modules/apple.js';
expect(eventsQueue).toHaveLength(1);
expect(eventsQueue).toEqual([{
filePath,
stat: statObject,
type: 'add',
}]);

expect(hasteFS.getModuleName(filePath)).toBeDefined();
next();
}),
);
},
];

next();
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ class HasteMap extends EventEmitter {
return Promise.resolve();
}

// In watch mode, we'll only warn about module collisions.
// In watch mode, we'll only warn about module collisions and we'll retain
// all files, even changes to node_modules.
this._options.throwOnModuleCollision = false;
this._options.retainAllFiles = true;

const Watcher = (canUseWatchman && this._options.useWatchman)
? sane.WatchmanWatcher
Expand Down Expand Up @@ -638,6 +640,9 @@ class HasteMap extends EventEmitter {
this._workerPromise = null;
if (promise) {
return promise.then(add);
} else {
// If a file in node_modules has changed, emit an event regardless.
add();
}
} else {
add();
Expand Down

0 comments on commit 174011c

Please sign in to comment.