From 274b84aa79706bf9584363903f28a7aca1b272b3 Mon Sep 17 00:00:00 2001 From: David Laban Date: Mon, 15 Jan 2018 10:12:06 +0000 Subject: [PATCH] make --lastCommit and --changedFilesWithAncestor work without --onlyChanged (#5307) * make --lastCommit and --changedFilesWithAncestor work without --onlyChanged * add fix to changelog --- CHANGELOG.md | 2 ++ docs/CLI.md | 8 +++--- .../jest-cli/src/__tests__/cli/args.test.js | 13 +++++++++ packages/jest-cli/src/cli/args.js | 27 +++++++++++-------- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c341855de20..209b1934add4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/CLI.md b/docs/CLI.md index a3da06c4b6fc..b9aa40ecbefb 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -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` @@ -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` diff --git a/packages/jest-cli/src/__tests__/cli/args.test.js b/packages/jest-cli/src/__tests__/cli/args.test.js index 5dc09760e5a5..ad53b7dcc31a 100644 --- a/packages/jest-cli/src/__tests__/cli/args.test.js +++ b/packages/jest-cli/src/__tests__/cli/args.test.js @@ -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( diff --git a/packages/jest-cli/src/cli/args.js b/packages/jest-cli/src/cli/args.js index f692493908ca..f56d513c8af3 100644 --- a/packages/jest-cli/src/cli/args.js +++ b/packages/jest-cli/src/cli/args.js @@ -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) { @@ -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: { @@ -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: { @@ -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: {