diff --git a/integration_tests/__tests__/only_changed.test.js b/integration_tests/__tests__/only_changed.test.js index d280c51de0c5..6e3bb9900a74 100644 --- a/integration_tests/__tests__/only_changed.test.js +++ b/integration_tests/__tests__/only_changed.test.js @@ -73,3 +73,60 @@ test('run only changed files', () => { expect(stderr).toMatch('PASS __tests__/file2.test.js'); expect(stderr).toMatch('PASS __tests__/file3.test.js'); }); + +test('onlyChanged in config is overwritten by --all', () => { + writeFiles(DIR, { + '.watchmanconfig': '', + '__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`, + 'file1.js': 'module.exports = {}', + 'package.json': JSON.stringify({jest: {onlyChanged: true}}), + }); + let stderr; + let stdout; + + ({stdout} = runJest(DIR)); + expect(stdout).toMatch(/Jest can only find uncommitted changed files/); + + run(`${GIT} init`, DIR); + run(`${GIT} add .`, DIR); + run(`${GIT} commit -m "first"`, DIR); + + ({stdout} = runJest(DIR)); + expect(stdout).toMatch('No tests found related to files'); + + ({stderr} = runJest(DIR, ['--lastCommit'])); + expect(stderr).toMatch('PASS __tests__/file1.test.js'); + + writeFiles(DIR, { + '__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, + '__tests__/file3.test.js': `require('../file3'); test('file3', () => {});`, + 'file2.js': 'module.exports = {}', + 'file3.js': `require('./file2')`, + }); + + ({stderr} = runJest(DIR)); + + expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); + + run(`${GIT} add .`, DIR); + run(`${GIT} commit -m "second"`, DIR); + + ({stderr} = runJest(DIR)); + expect(stdout).toMatch('No tests found related to files'); + + writeFiles(DIR, { + 'file2.js': 'module.exports = {modified: true}', + }); + + ({stderr} = runJest(DIR)); + expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); + + ({stderr} = runJest(DIR, ['--all'])); + expect(stderr).toMatch('PASS __tests__/file1.test.js'); + expect(stderr).toMatch('PASS __tests__/file2.test.js'); + expect(stderr).toMatch('PASS __tests__/file3.test.js'); +}); diff --git a/packages/jest-cli/src/cli/args.js b/packages/jest-cli/src/cli/args.js index 3ff7fee81696..9c1c03312ade 100644 --- a/packages/jest-cli/src/cli/args.js +++ b/packages/jest-cli/src/cli/args.js @@ -51,6 +51,13 @@ const usage = 'Usage: $0 [--config=] [TestPathPattern]'; const docs = 'Documentation: https://facebook.github.io/jest/'; const options = { + all: { + default: undefined, + description: + 'The opposite of `onlyChanged`. If `onlyChanged` is set by ' + + 'default, running jest with `--all` will force Jest to run all tests ' + + 'instead of runnig only tests related to changed files.', + }, automock: { default: undefined, description: 'Automock all files by default.', diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index a10c4dbc1d94..8f0084fd1090 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -492,6 +492,10 @@ function normalize(options: InitialOptions, argv: Argv) { newOptions.json = argv.json; newOptions.lastCommit = argv.lastCommit; + if (argv.all) { + newOptions.onlyChanged = false; + } + newOptions.updateSnapshot = argv.ci && !argv.updateSnapshot ? 'none' diff --git a/types/Argv.js b/types/Argv.js index d98a99f3e80f..25ae5c7a83b9 100644 --- a/types/Argv.js +++ b/types/Argv.js @@ -12,6 +12,7 @@ export type Argv = {| _: Array, $0: string, + all: boolean, automock: boolean, bail: boolean, browser: boolean,