Skip to content

Commit 62ddbe3

Browse files
committed
Update jest-haste-map ignorePattern to accept RegExp or Function
1 parent ad182a0 commit 62ddbe3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 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,
@@ -685,8 +685,14 @@ class HasteMap extends EventEmitter {
685685
* Helpers
686686
*/
687687
_ignore(filePath: Path): boolean {
688+
const ignorePattern = this._options.ignorePattern;
689+
const ignoreMatched =
690+
Object.prototype.toString.call(ignorePattern) === '[object RegExp]'
691+
? ignorePattern.test(filePath) // $FlowFixMe
692+
: ignorePattern(filePath);
693+
688694
return (
689-
this._options.ignorePattern.test(filePath) ||
695+
ignoreMatched ||
690696
(!this._options.retainAllFiles && this._isNodeModulesDir(filePath))
691697
);
692698
}

0 commit comments

Comments
 (0)