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 Jul 29, 2020
1 parent 1856fb2 commit a817726
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 68 deletions.
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module.exports = {
'/packages/jest-cli/src/init/__tests__/fixtures/',
'/packages/jest-haste-map/src/__tests__/haste_impl.js',
'/packages/jest-haste-map/src/__tests__/dependencyExtractor.js',
'/packages/jest-haste-map/src/__tests__/test_dotfiles_root',
'/packages/jest-resolve-dependencies/src/__tests__/__fixtures__/',
'/packages/jest-runtime/src/__tests__/defaultResolver.js',
'/packages/jest-runtime/src/__tests__/module_dir/',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"anymatch": "^3.0.3",
"fb-watchman": "^2.0.0",
"graceful-fs": "^4.2.4",
"jest-regex-util": "^26.0.0",
"jest-serializer": "^26.1.0",
"jest-util": "^26.1.0",
"jest-worker": "^26.1.0",
Expand Down
48 changes: 0 additions & 48 deletions packages/jest-haste-map/src/__tests__/includes_dotfiles.test.ts

This file was deleted.

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

This file was deleted.

This file was deleted.

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,7 @@ 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', '.hg'].map(vcs => '/' + vcs + '/').join('|');

// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't
// understand `require`.
Expand Down Expand Up @@ -233,7 +234,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 +250,26 @@ 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),
options.ignorePattern.flags,
);
} else {
const ignorePattern = options.ignorePattern;
const vcsIgnoreRegExp = new RegExp(VCS_DIRECTORIES);
this._options.ignorePattern = (filePath: string) =>
vcsIgnoreRegExp.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
1 change: 1 addition & 0 deletions packages/jest-haste-map/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"references": [
{"path": "../jest-worker"},
{"path": "../jest-serializer"},
{"path": "../jest-regex-util"},
{"path": "../jest-util"},
{"path": "../jest-types"}
]
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__metadata:
version: 4
cacheKey: 5
cacheKey: 6

"@angular/common@npm:^10.0.2":
version: 10.0.2
Expand Down Expand Up @@ -11213,6 +11213,7 @@ fsevents@^1.2.7:
fb-watchman: ^2.0.0
fsevents: ^2.1.2
graceful-fs: ^4.2.4
jest-regex-util: ^26.0.0
jest-serializer: ^26.1.0
jest-util: ^26.1.0
jest-worker: ^26.1.0
Expand Down

0 comments on commit a817726

Please sign in to comment.