Skip to content

Commit

Permalink
haste-map now ignores vcs directories
Browse files Browse the repository at this point in the history
  • Loading branch information
grosto committed Jun 11, 2020
1 parent 56bde2a commit 7af063f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
39 changes: 39 additions & 0 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ describe('HasteMap', () => {
});
});

it('ignores vcs directories without ignore pattern', () => {
mockFs['/project/fruits/.git/fruit-history.js'] = `
// test
`;
return new HasteMap(defaultConfig).build().then(({hasteFS}) => {
expect(hasteFS.matchFiles('.git')).toEqual([]);
});
});

it('ignores vcs directories with ignore pattern regex', () => {
const config = {...defaultConfig, ignorePattern: /Kiwi/};
mockFs['/project/fruits/Kiwi.js'] = `
// Kiwi!
`;

mockFs['/project/fruits/.git/fruit-history.js'] = `
// test
`;
return new HasteMap(config).build().then(({hasteFS}) => {
expect(hasteFS.matchFiles(/Kiwi/)).toEqual([]);
expect(hasteFS.matchFiles('.git')).toEqual([]);
});
});

it('ignores vcs directories with ignore pattern function', () => {
const config = {...defaultConfig, ignorePattern: f => /Kiwi/.test(f)};
mockFs['/project/fruits/Kiwi.js'] = `
// Kiwi!
`;

mockFs['/project/fruits/.git/fruit-history.js'] = `
// test
`;
return new HasteMap(config).build().then(({hasteFS}) => {
expect(hasteFS.matchFiles(/Kiwi/)).toEqual([]);
expect(hasteFS.matchFiles('.git')).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
27 changes: 21 additions & 6 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ const CHANGE_INTERVAL = 30;
const MAX_WAIT_TIME = 240000;
const NODE_MODULES = path.sep + 'node_modules' + path.sep;
const PACKAGE_JSON = path.sep + 'package.json';
const VCS_DIRECTORIES = ['.git', '.svn', '.hg']
.map(vcs => path.sep + vcs + path.sep)
.join('|');

// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't
// understand `require`.
Expand Down Expand Up @@ -233,7 +236,6 @@ class HasteMap extends EventEmitter {
extensions: options.extensions,
forceNodeFilesystemAPI: !!options.forceNodeFilesystemAPI,
hasteImplModulePath: options.hasteImplModulePath,
ignorePattern: options.ignorePattern,
maxWorkers: options.maxWorkers,
mocksPattern: options.mocksPattern
? new RegExp(options.mocksPattern)
Expand All @@ -250,11 +252,24 @@ class HasteMap extends EventEmitter {
watch: !!options.watch,
};
this._console = options.console || global.console;
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.',
);

if (options.ignorePattern) {
if (options.ignorePattern instanceof RegExp) {
this._options.ignorePattern = new RegExp(
options.ignorePattern.source.concat('|' + VCS_DIRECTORIES),
);
} else {
const ignorePattern = options.ignorePattern;
this._options.ignorePattern = (filePath: string) =>
new RegExp(VCS_DIRECTORIES).test(filePath) || ignorePattern(filePath);

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.',
);
}
} else {
this._options.ignorePattern = new RegExp(VCS_DIRECTORIES);
}

const rootDirHash = createHash('md5').update(options.rootDir).digest('hex');
Expand Down

0 comments on commit 7af063f

Please sign in to comment.