Skip to content

Commit 5d66ac3

Browse files
ro-savagecpojer
authored andcommitted
Fix bug with watchers on macOS causing test to crash (jestjs#2957)
* Update to pass ignorepath regex to sane * Changed jest-haste-map to pass modulePathIgnorePatterns * Update jest-haste-map ignorePattern to accept RegExp or Function
1 parent 0a77b0d commit 5d66ac3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/jest-haste-map/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"graceful-fs": "^4.1.6",
1313
"jest-docblock": "^19.0.2",
1414
"micromatch": "^2.3.11",
15-
"sane": "~1.5.0",
15+
"sane": "~1.6.0",
1616
"worker-farm": "^1.3.1"
1717
}
1818
}

packages/jest-haste-map/src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Options = {
4343
extensions: Array<string>,
4444
forceNodeFilesystemAPI?: boolean,
4545
hasteImplModulePath?: string,
46-
ignorePattern: RegExp,
46+
ignorePattern: RegExp | Function,
4747
maxWorkers: number,
4848
mocksPattern?: string,
4949
name: string,
@@ -62,7 +62,7 @@ type InternalOptions = {
6262
extensions: Array<string>,
6363
forceNodeFilesystemAPI: boolean,
6464
hasteImplModulePath?: string,
65-
ignorePattern: RegExp,
65+
ignorePattern: RegExp | Function,
6666
maxWorkers: number,
6767
mocksPattern: ?RegExp,
6868
name: string,
@@ -533,6 +533,7 @@ class HasteMap extends EventEmitter {
533533
? sane.WatchmanWatcher
534534
: sane.NodeWatcher;
535535
const extensions = this._options.extensions;
536+
const ignorePattern = this._options.ignorePattern;
536537
let changeQueue = Promise.resolve();
537538
let eventsQueue = [];
538539
// We only need to copy the entire haste map once on every "frame".
@@ -544,6 +545,7 @@ class HasteMap extends EventEmitter {
544545
const watcher = new Watcher(root, {
545546
dot: false,
546547
glob: extensions.map(extension => '**/*.' + extension),
548+
ignored: ignorePattern,
547549
});
548550

549551
return new Promise((resolve, reject) => {
@@ -686,7 +688,13 @@ class HasteMap extends EventEmitter {
686688
* Helpers
687689
*/
688690
_ignore(filePath: Path): boolean {
689-
return this._options.ignorePattern.test(filePath) ||
691+
const ignorePattern = this._options.ignorePattern;
692+
const ignoreMatched =
693+
Object.prototype.toString.call(ignorePattern) === '[object RegExp]'
694+
? ignorePattern.test(filePath) // $FlowFixMe
695+
: ignorePattern(filePath);
696+
697+
return ignoreMatched ||
690698
(!this._options.retainAllFiles && this._isNodeModulesDir(filePath));
691699
}
692700

0 commit comments

Comments
 (0)