Skip to content

Commit 274b84a

Browse files
alsurencpojer
authored andcommitted
make --lastCommit and --changedFilesWithAncestor work without --onlyChanged (#5307)
* make --lastCommit and --changedFilesWithAncestor work without --onlyChanged * add fix to changelog
1 parent 634e474 commit 274b84a

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
([#5289](https://github.com/facebook/jest/pull/5289))
1414
* `[docs]` Update mention of the minimal version of node supported [#4947](https://github.com/facebook/jest/issues/4947)
1515
* `[jest-cli]` Fix missing newline in console message ([#5308](https://github.com/facebook/jest/pull/5308))
16+
* `[jest-cli]` `--lastCommit` and `--changedFilesWithAncestor` now take effect
17+
even when `--onlyChanged` is not specified. ([#5307](https://github.com/facebook/jest/pull/5307))
1618

1719
### Chore & Maintenance
1820

docs/CLI.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ If you want to inspect the cache, use `--showConfig` and look at the
105105

106106
### `--changedFilesWithAncestor`
107107

108-
When used together with `--onlyChanged` or `--watch`, it runs tests related to
109-
the current changes and the changes made in the last commit.
108+
Runs tests related to the current changes and the changes made in the last
109+
commit. Behaves similarly to `--onlyChanged`.
110110

111111
### `--ci`
112112

@@ -188,8 +188,8 @@ Write test results to a file when the `--json` option is also specified.
188188

189189
### `--lastCommit`
190190

191-
When used together with `--onlyChanged`, it will run all tests affected by file
192-
changes in the last commit made.
191+
Run all tests affected by file changes in the last commit made. Behaves
192+
similarly to `--onlyChanged`.
193193

194194
### `--listTests`
195195

packages/jest-cli/src/__tests__/cli/args.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ describe('check', () => {
3131
);
3232
});
3333

34+
it('raises an exception when lastCommit and watchAll are both specified', () => {
35+
const argv: Argv = {lastCommit: true, watchAll: true};
36+
expect(() => check(argv)).toThrow(
37+
'Both --lastCommit and --watchAll were specified',
38+
);
39+
});
40+
41+
it('sets onlyChanged if lastCommit is specified', () => {
42+
const argv: Argv = {lastCommit: true};
43+
check(argv);
44+
expect(argv.onlyChanged).toBe(true);
45+
});
46+
3447
it('raises an exception if findRelatedTests is specified with no file paths', () => {
3548
const argv: Argv = {_: [], findRelatedTests: true};
3649
expect(() => check(argv)).toThrow(

packages/jest-cli/src/cli/args.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ export const check = (argv: Argv) => {
2020
);
2121
}
2222

23-
if (argv.onlyChanged && argv.watchAll) {
24-
throw new Error(
25-
'Both --onlyChanged and --watchAll were specified, but these two ' +
26-
'options do not make sense together. Try the --watch option which ' +
27-
'reruns only tests related to changed files.',
28-
);
23+
for (const key of ['onlyChanged', 'lastCommit', 'changedFilesWithAncestor']) {
24+
if (argv[key]) {
25+
argv.onlyChanged = true;
26+
}
27+
if (argv[key] && argv.watchAll) {
28+
throw new Error(
29+
`Both --${key} and --watchAll were specified, but these two ` +
30+
'options do not make sense together. Try the --watch option which ' +
31+
'reruns only tests related to changed files.',
32+
);
33+
}
2934
}
3035

3136
if (argv.findRelatedTests && argv._.length === 0) {
@@ -104,8 +109,8 @@ export const options = {
104109
},
105110
changedFilesWithAncestor: {
106111
description:
107-
'When used together with `--onlyChanged` or `--watch`, it runs tests ' +
108-
'related to the current changes and the changes made in the last commit. ',
112+
'Runs tests related to the current changes and the changes made in the ' +
113+
'last commit. Behaves similarly to `--onlyChanged`.',
109114
type: 'boolean',
110115
},
111116
ci: {
@@ -267,8 +272,8 @@ export const options = {
267272
lastCommit: {
268273
default: undefined,
269274
description:
270-
'When used together with `--onlyChanged`, it will run all tests ' +
271-
'affected by file changes in the last commit made.',
275+
'Run all tests affected by file changes in the last commit made. ' +
276+
'Behaves similarly to `--onlyChanged`.',
272277
type: 'boolean',
273278
},
274279
listTests: {
@@ -353,7 +358,7 @@ export const options = {
353358
description:
354359
'Attempts to identify which tests to run based on which ' +
355360
"files have changed in the current repository. Only works if you're " +
356-
'running tests in a git repository at the moment.',
361+
'running tests in a git or hg repository at the moment.',
357362
type: 'boolean',
358363
},
359364
onlyFailures: {

0 commit comments

Comments
 (0)