Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with watchers on macOS causing test to crash #2957

Merged
merged 3 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do ignorePattern instanceof RegExp, maybe flow understands that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that worked actually. Will submit another PR to make that change. Thanks for the tip Simen.

? ignorePattern.test(filePath) // $FlowFixMe
: ignorePattern(filePath);

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

Expand Down