Skip to content

Commit

Permalink
make --lastCommit and --changedFilesWithAncestor work without --onlyC…
Browse files Browse the repository at this point in the history
…hanged
  • Loading branch information
alsuren committed Jan 14, 2018
1 parent c9cf010 commit fc53821
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
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 fc53821

Please sign in to comment.