Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watchPathIgnorePatterns to exclude paths to trigger test re-run in watch mode #4331

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
\\"timers\\": \\"real\\",
\\"transformIgnorePatterns\\": [
\\"/node_modules/\\"
]
],
\\"watchPathIgnorePatterns\\": []
}
],
\\"globalConfig\\": {
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,13 @@ const options = {
'`--watch` option.',
type: 'boolean',
},
watchPathIgnorePatterns: {
description:
'An array of regexp pattern strings that are matched ' +
'against all paths before trigger test re-run in watch mode. ' +
'If the test path matches any of the patterns, it will be skipped.',
type: 'array',
},
watchman: {
default: undefined,
description:
Expand Down
11 changes: 11 additions & 0 deletions packages/jest-cli/src/lib/__tests__/is_valid_path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const rootDir = path.resolve(path.sep, 'root');
const config = makeProjectConfig({
rootDir,
roots: [path.resolve(rootDir, 'src'), path.resolve(rootDir, 'lib')],
watchPathIgnorePatterns: ['pacts/'],
});

it('is valid when it is a file inside roots', () => {
Expand Down Expand Up @@ -87,3 +88,13 @@ it('is not valid when it is a file in the coverage dir', () => {
),
).toBe(false);
});

it('is not valid when it is a file match one of the watchPathIgnorePatterns', () => {
expect(
isValidPath(
makeGlobalConfig({rootDir}),
config,
path.resolve(rootDir, 'pacts', 'todoapp-todoservice.json'),
),
).toBe(false);
});
1 change: 1 addition & 0 deletions packages/jest-cli/src/lib/is_valid_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function isValidPath(
) {
return (
!filePath.includes(globalConfig.coverageDirectory) &&
!config.watchPathIgnorePatterns.some(pattern => filePath.match(pattern)) &&
!filePath.endsWith(`.${SNAPSHOT_EXTENSION}`)
);
}
Expand Down
51 changes: 51 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,57 @@ describe('coveragePathIgnorePatterns', () => {
});
});

describe('watchPathIgnorePatterns', () => {
it('does not normalize paths relative to rootDir', () => {
// This is a list of patterns, so we can't assume any of them are
// directories
const {options} = normalize(
{
rootDir: '/root/path/foo',
watchPathIgnorePatterns: ['bar/baz', 'qux/quux'],
},
{},
);

expect(options.watchPathIgnorePatterns).toEqual([
joinForPattern('bar', 'baz'),
joinForPattern('qux', 'quux'),
]);
});

it('does not normalize trailing slashes', () => {
// This is a list of patterns, so we can't assume any of them are
// directories
const {options} = normalize(
{
rootDir: '/root/path/foo',
watchPathIgnorePatterns: ['bar/baz', 'qux/quux/'],
},
{},
);

expect(options.watchPathIgnorePatterns).toEqual([
joinForPattern('bar', 'baz'),
joinForPattern('qux', 'quux', ''),
]);
});

it('substitutes <rootDir> tokens', () => {
const {options} = normalize(
{
rootDir: '/root/path/foo',
watchPathIgnorePatterns: ['hasNoToken', '<rootDir>/hasAToken'],
},
{},
);

expect(options.watchPathIgnorePatterns).toEqual([
'hasNoToken',
joinForPattern('', 'root', 'path', 'foo', 'hasAToken'),
]);
});
});

describe('testPathIgnorePatterns', () => {
it('does not normalize paths relative to rootDir', () => {
// This is a list of patterns, so we can't assume any of them are
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ module.exports = ({
useStderr: false,
verbose: null,
watch: false,
watchPathIgnorePatterns: [],
watchman: true,
}: DefaultOptions);
1 change: 1 addition & 0 deletions packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const getConfigs = (
transform: options.transform,
transformIgnorePatterns: options.transformIgnorePatterns,
unmockedModulePathPatterns: options.unmockedModulePathPatterns,
watchPathIgnorePatterns: options.watchPathIgnorePatterns,
}),
};
};
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ function normalize(options: InitialOptions, argv: Argv) {
case 'modulePathIgnorePatterns':
case 'testPathIgnorePatterns':
case 'transformIgnorePatterns':
case 'watchPathIgnorePatterns':
case 'unmockedModulePathPatterns':
value = normalizeUnmockedModulePathPatterns(options, key);
break;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/valid_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ module.exports = ({
useStderr: false,
verbose: false,
watch: false,
watchPathIgnorePatterns: [],
watchman: true,
}: InitialOptions);
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const defaultConfig = {
useStderr: false,
verbose: null,
watch: false,
watchPathIgnorePatterns: [],
};

const validConfig = {
Expand Down
1 change: 1 addition & 0 deletions test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
transform: [],
transformIgnorePatterns: [],
unmockedModulePathPatterns: null,
watchPathIgnorePatterns: [],
};

const makeGlobalConfig = (overrides: Object = {}): GlobalConfig => {
Expand Down
1 change: 1 addition & 0 deletions types/Argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export type Argv = {|
timers: 'real' | 'fake',
transform: string,
transformIgnorePatterns: Array<string>,
watchPathIgnorePatterns: Array<string>,
unmockedModulePathPatterns: ?Array<string>,
updateSnapshot: boolean,
useStderr: boolean,
Expand Down
3 changes: 3 additions & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type DefaultOptions = {|
testURL: string,
timers: 'real' | 'fake',
transformIgnorePatterns: Array<Glob>,
watchPathIgnorePatterns: Array<string>,
useStderr: boolean,
verbose: ?boolean,
watch: boolean,
Expand Down Expand Up @@ -126,6 +127,7 @@ export type InitialOptions = {
timers?: 'real' | 'fake',
transform?: {[key: string]: string},
transformIgnorePatterns?: Array<Glob>,
watchPathIgnorePatterns?: Array<string>,
unmockedModulePathPatterns?: Array<string>,
updateSnapshot?: boolean,
useStderr?: boolean,
Expand Down Expand Up @@ -213,5 +215,6 @@ export type ProjectConfig = {|
timers: 'real' | 'fake',
transform: Array<[string, Path]>,
transformIgnorePatterns: Array<Glob>,
watchPathIgnorePatterns: Array<string>,
unmockedModulePathPatterns: ?Array<string>,
|};