Skip to content

Commit

Permalink
Make ignorePattern optional in HasteMap
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Oct 15, 2018
1 parent 1480d84 commit 03199e5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- `[jest-haste-map]` [**BREAKING**] Remove support for `@providesModule` ([#6104](https://github.com/facebook/jest/pull/6104))
- `[pretty-format]` Support HTMLCollection and NodeList in DOMCollection plugin ([#7125](https://github.com/facebook/jest/pull/7125))
- `[jest-runtime]` Pass the normalized configuration to script transformers ([#7148](https://github.com/facebook/jest/pull/7148))
- `[jest-haste-map]` Make `ignorePattern` optional ([#7166](https://github.com/facebook/jest/pull/7166))
- `[jest-runtime]` Remove `cacheDirectory` from `ignorePattern` for `HasteMap` if not necessary ([#7166](https://github.com/facebook/jest/pull/7166))

### Fixes

Expand Down
14 changes: 10 additions & 4 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ describe('HasteMap', () => {
'/project/fruits/Banana.js': `
const Strawberry = require("Strawberry");
`,
'/project/fruits/Kiwi.js': `
// Kiwi!
`,
'/project/fruits/Pear.js': `
const Banana = require("Banana");
const Strawberry = require("Strawberry");
Expand Down Expand Up @@ -189,7 +186,6 @@ describe('HasteMap', () => {
defaultConfig = {
extensions: ['js', 'json'],
hasteImplModulePath: require.resolve('./haste_impl.js'),
ignorePattern: /Kiwi/,
maxWorkers: 1,
name: 'haste-map-test',
platforms: ['ios', 'android'],
Expand Down Expand Up @@ -237,6 +233,16 @@ describe('HasteMap', () => {
]);
}));

it('ignores files given a pattern', () => {
const config = Object.assign({}, defaultConfig, {ignorePattern: /Kiwi/});
mockFs['/project/fruits/Kiwi.js'] = `
// Kiwi!
`;
return new HasteMap(config).build().then(({hasteFS}) => {
expect(hasteFS.matchFiles(/Kiwi/)).toEqual([]);
});
});

it('builds a haste map on a fresh cache', () => {
// Include these files in the map
mockFs['/project/fruits/node_modules/react/React.js'] = `
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Options = {
extensions: Array<string>,
forceNodeFilesystemAPI?: boolean,
hasteImplModulePath?: string,
ignorePattern: HasteRegExp,
ignorePattern?: ?HasteRegExp,
maxWorkers: number,
mocksPattern?: string,
name: string,
Expand All @@ -76,7 +76,7 @@ type InternalOptions = {
extensions: Array<string>,
forceNodeFilesystemAPI: boolean,
hasteImplModulePath?: string,
ignorePattern: HasteRegExp,
ignorePattern: ?HasteRegExp,
maxWorkers: number,
mocksPattern: ?RegExp,
name: string,
Expand Down Expand Up @@ -249,7 +249,7 @@ class HasteMap extends EventEmitter {
watch: !!options.watch,
};
this._console = options.console || global.console;
if (!(options.ignorePattern instanceof RegExp)) {
if (options.ignorePattern && !(options.ignorePattern instanceof RegExp)) {
this._console.warn(
'jest-haste-map: the `ignorePattern` options as a function is being ' +
'deprecated. Provide a RegExp instead. See https://github.com/facebook/jest/pull/4063.',
Expand All @@ -270,7 +270,7 @@ class HasteMap extends EventEmitter {
this._options.platforms.join(':'),
this._options.computeSha1.toString(),
options.mocksPattern || '',
options.ignorePattern.toString(),
(options.ignorePattern || '').toString(),
);
this._whitelist = getWhiteList(options.providesModuleNodeModules);
this._buildPromise = null;
Expand Down Expand Up @@ -966,7 +966,7 @@ class HasteMap extends EventEmitter {
const ignoreMatched =
ignorePattern instanceof RegExp
? ignorePattern.test(filePath)
: ignorePattern(filePath);
: ignorePattern && ignorePattern(filePath);

return (
ignoreMatched ||
Expand Down
12 changes: 9 additions & 3 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,15 @@ class Runtime {
config: ProjectConfig,
options?: HasteMapOptions,
): HasteMap {
const ignorePattern = new RegExp(
[config.cacheDirectory].concat(config.modulePathIgnorePatterns).join('|'),
);
const ignorePatternParts = [
...config.modulePathIgnorePatterns,
config.cacheDirectory.startsWith(config.rootDir + path.sep) &&
config.cacheDirectory,
].filter(Boolean);
const ignorePattern =
ignorePatternParts.length > 0
? new RegExp(ignorePatternParts.join('|'))
: null;

return new HasteMap({
cacheDirectory: config.cacheDirectory,
Expand Down

0 comments on commit 03199e5

Please sign in to comment.