Skip to content

Commit

Permalink
Fix bug with watchers on macOS causing test to crash (jestjs#2957)
Browse files Browse the repository at this point in the history
* Update to pass ignorepath regex to sane

* Changed jest-haste-map to pass modulePathIgnorePatterns

* Update jest-haste-map ignorePattern to accept RegExp or Function
  • Loading branch information
ro-savage authored and skovhus committed Apr 29, 2017
1 parent 6571750 commit 1108cc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"graceful-fs": "^4.1.6",
"jest-docblock": "^19.0.2",
"micromatch": "^2.3.11",
"sane": "~1.5.0",
"sane": "~1.6.0",
"worker-farm": "^1.3.1"
}
}
14 changes: 11 additions & 3 deletions packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Options = {
extensions: Array<string>,
forceNodeFilesystemAPI?: boolean,
hasteImplModulePath?: string,
ignorePattern: RegExp,
ignorePattern: RegExp | Function,
maxWorkers: number,
mocksPattern?: string,
name: string,
Expand All @@ -62,7 +62,7 @@ type InternalOptions = {
extensions: Array<string>,
forceNodeFilesystemAPI: boolean,
hasteImplModulePath?: string,
ignorePattern: RegExp,
ignorePattern: RegExp | Function,
maxWorkers: number,
mocksPattern: ?RegExp,
name: string,
Expand Down Expand Up @@ -533,6 +533,7 @@ class HasteMap extends EventEmitter {
? sane.WatchmanWatcher
: sane.NodeWatcher;
const extensions = this._options.extensions;
const ignorePattern = this._options.ignorePattern;
let changeQueue = Promise.resolve();
let eventsQueue = [];
// We only need to copy the entire haste map once on every "frame".
Expand All @@ -544,6 +545,7 @@ class HasteMap extends EventEmitter {
const watcher = new Watcher(root, {
dot: false,
glob: extensions.map(extension => '**/*.' + extension),
ignored: ignorePattern,
});

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -686,7 +688,13 @@ class HasteMap extends EventEmitter {
* Helpers
*/
_ignore(filePath: Path): boolean {
return this._options.ignorePattern.test(filePath) ||
const ignorePattern = this._options.ignorePattern;
const ignoreMatched =
Object.prototype.toString.call(ignorePattern) === '[object RegExp]'
? ignorePattern.test(filePath) // $FlowFixMe
: ignorePattern(filePath);

return ignoreMatched ||
(!this._options.retainAllFiles && this._isNodeModulesDir(filePath));
}

Expand Down

0 comments on commit 1108cc3

Please sign in to comment.