Skip to content

Commit 33fba2c

Browse files
thymikeecaptain-yossarian
authored andcommitted
fix: Pass watchPathIgnorePatterns to Haste instance (jestjs#7585)
1 parent dfbc36c commit 33fba2c

File tree

6 files changed

+52
-38
lines changed

6 files changed

+52
-38
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
- `[jest-environment-node]` Fix buffer property is not ArrayBuffer issue. ([#7626](https://github.com/facebook/jest/pull/7626))
122122
- `[babel-plugin-jest-hoist]` Ignore TS type annotations when looking for out-of-scope references ([#7641](https://github.com/facebook/jest/pull/7641))
123123
- `[jest-config]` Add name to project if one does not exist to pick correct resolver ([#5862](https://github.com/facebook/jest/pull/5862))
124+
- `[jest-runtime]` Pass `watchPathIgnorePatterns` to Haste instance ([#7585](https://github.com/facebook/jest/pull/7585))
124125

125126
### Chore & Maintenance
126127

packages/jest-cli/src/lib/__tests__/is_valid_path.test.js

+3-34
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,24 @@
88
*/
99

1010
import isValidPath from '../is_valid_path';
11-
12-
const path = require('path');
13-
const {
14-
makeGlobalConfig,
15-
makeProjectConfig,
16-
} = require('../../../../../TestUtils');
11+
import path from 'path';
12+
import {makeGlobalConfig} from '../../../../../TestUtils';
1713

1814
const rootDir = path.resolve(path.sep, 'root');
1915

20-
const config = makeProjectConfig({
21-
rootDir,
22-
roots: [path.resolve(rootDir, 'src'), path.resolve(rootDir, 'lib')],
23-
watchPathIgnorePatterns: ['pacts'],
24-
});
25-
2616
it('is valid when it is a file inside roots', () => {
2717
expect(
28-
isValidPath(
29-
makeGlobalConfig(),
30-
config,
31-
path.resolve(rootDir, 'src', 'index.js'),
32-
),
18+
isValidPath(makeGlobalConfig(), path.resolve(rootDir, 'src', 'index.js')),
3319
).toBe(true);
3420
expect(
3521
isValidPath(
3622
makeGlobalConfig(),
37-
config,
3823
path.resolve(rootDir, 'src', 'components', 'Link.js'),
3924
),
4025
).toBe(true);
4126
expect(
4227
isValidPath(
4328
makeGlobalConfig(),
44-
config,
4529
path.resolve(rootDir, 'src', 'lib', 'something.js'),
4630
),
4731
).toBe(true);
@@ -51,21 +35,18 @@ it('is not valid when it is a snapshot file', () => {
5135
expect(
5236
isValidPath(
5337
makeGlobalConfig(),
54-
config,
5538
path.resolve(rootDir, 'src', 'index.js.snap'),
5639
),
5740
).toBe(false);
5841
expect(
5942
isValidPath(
6043
makeGlobalConfig(),
61-
config,
6244
path.resolve(rootDir, 'src', 'components', 'Link.js.snap'),
6345
),
6446
).toBe(false);
6547
expect(
6648
isValidPath(
6749
makeGlobalConfig(),
68-
config,
6950
path.resolve(rootDir, 'src', 'lib', 'something.js.snap'),
7051
),
7152
).toBe(false);
@@ -75,26 +56,14 @@ it('is not valid when it is a file in the coverage dir', () => {
7556
expect(
7657
isValidPath(
7758
makeGlobalConfig({rootDir}),
78-
config,
7959
path.resolve(rootDir, 'coverage', 'lib', 'index.js'),
8060
),
8161
).toBe(false);
8262

8363
expect(
8464
isValidPath(
8565
makeGlobalConfig({coverageDirectory: 'cov-dir'}),
86-
config,
8766
path.resolve(rootDir, 'src', 'cov-dir', 'lib', 'index.js'),
8867
),
8968
).toBe(false);
9069
});
91-
92-
it('is not valid when it is a file match one of the watchPathIgnorePatterns', () => {
93-
expect(
94-
isValidPath(
95-
makeGlobalConfig({rootDir}),
96-
config,
97-
path.resolve(rootDir, 'pacts', 'todoapp-todoservice.json'),
98-
),
99-
).toBe(false);
100-
});

packages/jest-cli/src/lib/is_valid_path.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
* @flow
88
*/
99

10-
import type {GlobalConfig, ProjectConfig} from 'types/Config';
10+
import type {GlobalConfig} from 'types/Config';
1111
import {isSnapshotPath} from 'jest-snapshot';
1212

1313
export default function isValidPath(
1414
globalConfig: GlobalConfig,
15-
config: ProjectConfig,
1615
filePath: string,
1716
) {
1817
return (
1918
!filePath.includes(globalConfig.coverageDirectory) &&
20-
!config.watchPathIgnorePatterns.some(pattern => filePath.match(pattern)) &&
2119
!isSnapshotPath(filePath)
2220
);
2321
}

packages/jest-cli/src/watch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default function watch(
194194
hasteMapInstances.forEach((hasteMapInstance, index) => {
195195
hasteMapInstance.on('change', ({eventsQueue, hasteFS, moduleMap}) => {
196196
const validPaths = eventsQueue.filter(({filePath}) =>
197-
isValidPath(globalConfig, contexts[index].config, filePath),
197+
isValidPath(globalConfig, filePath),
198198
);
199199

200200
if (validPaths.length) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
import HasteMap from 'jest-haste-map';
10+
const Runtime = require('../');
11+
12+
jest.mock('jest-haste-map');
13+
14+
describe('Runtime statics', () => {
15+
const projectConfig = {
16+
cacheDirectory: '/tmp',
17+
haste: {},
18+
modulePathIgnorePatterns: ['/root/ignore-1', '/root/ignore-2'],
19+
watchPathIgnorePatterns: ['/watch-root/ignore-1'],
20+
};
21+
const options = {};
22+
23+
beforeEach(() => {
24+
jest.clearAllMocks();
25+
});
26+
27+
test('Runtime.createHasteMap passes correct ignore files to HasteMap', () => {
28+
Runtime.createHasteMap(projectConfig, options);
29+
expect(HasteMap).toBeCalledWith(
30+
expect.objectContaining({
31+
ignorePattern: /\/root\/ignore-1|\/root\/ignore-2/,
32+
}),
33+
);
34+
});
35+
36+
test('Runtime.createHasteMap passes correct ignore files to HasteMap in watch mode', () => {
37+
Runtime.createHasteMap(projectConfig, {...options, watch: true});
38+
expect(HasteMap).toBeCalledWith(
39+
expect.objectContaining({
40+
ignorePattern: /\/root\/ignore-1|\/root\/ignore-2|\/watch-root\/ignore-1/,
41+
watch: true,
42+
}),
43+
);
44+
});
45+
});

packages/jest-runtime/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class Runtime {
229229
): HasteMap {
230230
const ignorePatternParts = [
231231
...config.modulePathIgnorePatterns,
232+
...(options && options.watch ? config.watchPathIgnorePatterns : []),
232233
config.cacheDirectory.startsWith(config.rootDir + path.sep) &&
233234
config.cacheDirectory,
234235
].filter(Boolean);

0 commit comments

Comments
 (0)