Skip to content

Commit 29c7980

Browse files
rogeliogcpojer
authored andcommitted
Filter snap file changes in watch mode (#2833)
* Filter snap file changes in watch mode * Change onlySnapFileEvents to hasOnlySnapshotChanges
1 parent 204e46c commit 29c7980

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

packages/jest-cli/src/watch.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const SearchSource = require('./SearchSource');
2424
const TestWatcher = require('./TestWatcher');
2525
const {KEYS, CLEAR} = require('./constants');
2626

27+
const SNAPSHOT_EXTENSION = 'snap';
28+
2729
const watch = (
2830
config: Config,
2931
pipe: stream$Writable | tty$WriteStream,
@@ -43,12 +45,18 @@ const watch = (
4345
let displayHelp = true;
4446
let searchSource = new SearchSource(hasteContext, config);
4547

46-
hasteMap.on('change', ({hasteFS, moduleMap}) => {
47-
hasteContext = createHasteContext(config, {hasteFS, moduleMap});
48-
currentPattern = '';
49-
isEnteringPattern = false;
50-
searchSource = new SearchSource(hasteContext, config);
51-
startRun();
48+
hasteMap.on('change', ({eventsQueue, hasteFS, moduleMap}) => {
49+
const hasOnlySnapshotChanges = eventsQueue.every(({filePath}) => {
50+
return filePath.endsWith(`.${SNAPSHOT_EXTENSION}`);
51+
});
52+
53+
if (!hasOnlySnapshotChanges) {
54+
hasteContext = createHasteContext(config, {hasteFS, moduleMap});
55+
currentPattern = '';
56+
isEnteringPattern = false;
57+
searchSource = new SearchSource(hasteContext, config);
58+
startRun();
59+
}
5260
});
5361

5462
process.on('exit', () => {

0 commit comments

Comments
 (0)