Skip to content

Commit

Permalink
jest --all
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Jul 12, 2017
1 parent 6e56c6e commit a5de829
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
57 changes: 57 additions & 0 deletions integration_tests/__tests__/only_changed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
7 changes: 7 additions & 0 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const usage = 'Usage: $0 [--config=<pathToConfigFile>] [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.',
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a5de829

Please sign in to comment.