Skip to content

Commit

Permalink
make --lastCommit and --changedFilesWithAncestor work without --onlyC…
Browse files Browse the repository at this point in the history
…hanged (#5307)

* make --lastCommit and --changedFilesWithAncestor work without --onlyChanged

* add fix to changelog
  • Loading branch information
alsuren authored and cpojer committed Jan 15, 2018
1 parent 634e474 commit 274b84a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
([#5289](https://github.com/facebook/jest/pull/5289))
* `[docs]` Update mention of the minimal version of node supported [#4947](https://github.com/facebook/jest/issues/4947)
* `[jest-cli]` Fix missing newline in console message ([#5308](https://github.com/facebook/jest/pull/5308))
* `[jest-cli]` `--lastCommit` and `--changedFilesWithAncestor` now take effect
even when `--onlyChanged` is not specified. ([#5307](https://github.com/facebook/jest/pull/5307))

### Chore & Maintenance

Expand Down
8 changes: 4 additions & 4 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ If you want to inspect the cache, use `--showConfig` and look at the

### `--changedFilesWithAncestor`

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

### `--ci`

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

### `--lastCommit`

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

### `--listTests`

Expand Down
13 changes: 13 additions & 0 deletions packages/jest-cli/src/__tests__/cli/args.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ describe('check', () => {
);
});

it('raises an exception when lastCommit and watchAll are both specified', () => {
const argv: Argv = {lastCommit: true, watchAll: true};
expect(() => check(argv)).toThrow(
'Both --lastCommit and --watchAll were specified',
);
});

it('sets onlyChanged if lastCommit is specified', () => {
const argv: Argv = {lastCommit: true};
check(argv);
expect(argv.onlyChanged).toBe(true);
});

it('raises an exception if findRelatedTests is specified with no file paths', () => {
const argv: Argv = {_: [], findRelatedTests: true};
expect(() => check(argv)).toThrow(
Expand Down
27 changes: 16 additions & 11 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ export const check = (argv: Argv) => {
);
}

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

if (argv.findRelatedTests && argv._.length === 0) {
Expand Down Expand Up @@ -104,8 +109,8 @@ export const options = {
},
changedFilesWithAncestor: {
description:
'When used together with `--onlyChanged` or `--watch`, it runs tests ' +
'related to the current changes and the changes made in the last commit. ',
'Runs tests related to the current changes and the changes made in the ' +
'last commit. Behaves similarly to `--onlyChanged`.',
type: 'boolean',
},
ci: {
Expand Down Expand Up @@ -267,8 +272,8 @@ export const options = {
lastCommit: {
default: undefined,
description:
'When used together with `--onlyChanged`, it will run all tests ' +
'affected by file changes in the last commit made.',
'Run all tests affected by file changes in the last commit made. ' +
'Behaves similarly to `--onlyChanged`.',
type: 'boolean',
},
listTests: {
Expand Down Expand Up @@ -353,7 +358,7 @@ export const options = {
description:
'Attempts to identify which tests to run based on which ' +
"files have changed in the current repository. Only works if you're " +
'running tests in a git repository at the moment.',
'running tests in a git or hg repository at the moment.',
type: 'boolean',
},
onlyFailures: {
Expand Down

0 comments on commit 274b84a

Please sign in to comment.