Skip to content

Commit

Permalink
Keep ARGV only in CLI files
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Jul 11, 2017
1 parent eb81364 commit 6b28cf2
Show file tree
Hide file tree
Showing 28 changed files with 420 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ Object {
"christoph": "pojer",
"dmitrii": "abramov",
"hello": "world",
"pattern": Object {
"input": "add_fail.test.js",
"paths": Array [
"add_fail.test.js",
],
"shouldTreatInputAsPattern": false,
"testPathPattern": "add_fail.test.js",
},
"testPathPattern": "\\"add_fail.test.js\\"",
},
}
`;
Expand Down Expand Up @@ -69,15 +60,6 @@ Object {
"christoph": "pojer",
"dmitrii": "abramov",
"hello": "world",
"pattern": Object {
"input": "add.test.js",
"paths": Array [
"add.test.js",
],
"shouldTreatInputAsPattern": false,
"testPathPattern": "add.test.js",
},
"testPathPattern": "\\"add.test.js\\"",
},
}
`;
Expand All @@ -95,7 +77,7 @@ exports[`Custom Reporters Integration default reporters enabled 2`] = `
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"add.test.js\\".
Ran all test suites matching /add.test.js/i.
"
`;
Expand All @@ -119,17 +101,7 @@ Object {
"called": true,
"path": false,
},
"options": Object {
"pattern": Object {
"input": "add.test.js",
"paths": Array [
"add.test.js",
],
"shouldTreatInputAsPattern": false,
"testPathPattern": "add.test.js",
},
"testPathPattern": "\\"add.test.js\\"",
},
"options": Object {},
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
"clover"
],
"expand": false,
"listTests": false,
"mapCoverage": false,
"maxWorkers": "[maxWorkers]",
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"rootDir": "/mocked/root/path/jest/integration_tests/verbose_reporter",
"testPathPattern": "",
Expand Down
14 changes: 7 additions & 7 deletions integration_tests/__tests__/__snapshots__/snapshot.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports[`Snapshot works with escaped characters 1`] = `
Tests: 1 passed, 1 total
Snapshots: 1 added, 1 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot.test.js\\".
Ran all test suites matching /snapshot.test.js/i.
"
`;
Expand All @@ -104,7 +104,7 @@ exports[`Snapshot works with escaped characters 2`] = `
Tests: 2 passed, 2 total
Snapshots: 1 added, 1 passed, 2 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot.test.js\\".
Ran all test suites matching /snapshot.test.js/i.
"
`;
Expand All @@ -113,7 +113,7 @@ exports[`Snapshot works with escaped characters 3`] = `
Tests: 2 passed, 2 total
Snapshots: 2 passed, 2 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot.test.js\\".
Ran all test suites matching /snapshot.test.js/i.
"
`;
Expand All @@ -122,7 +122,7 @@ exports[`Snapshot works with escaped regex 1`] = `
Tests: 2 passed, 2 total
Snapshots: 2 added, 2 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot_escape_regex.js\\".
Ran all test suites matching /snapshot_escape_regex.js/i.
"
`;
Expand All @@ -131,7 +131,7 @@ exports[`Snapshot works with escaped regex 2`] = `
Tests: 2 passed, 2 total
Snapshots: 2 passed, 2 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot_escape_regex.js\\".
Ran all test suites matching /snapshot_escape_regex.js/i.
"
`;
Expand All @@ -140,7 +140,7 @@ exports[`Snapshot works with template literal subsitutions 1`] = `
Tests: 1 passed, 1 total
Snapshots: 1 added, 1 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot_escape_substitution.test.js\\".
Ran all test suites matching /snapshot_escape_substitution.test.js/i.
"
`;
Expand All @@ -149,6 +149,6 @@ exports[`Snapshot works with template literal subsitutions 2`] = `
Tests: 1 passed, 1 total
Snapshots: 1 passed, 1 total
Time: <<REPLACED>>
Ran all test suites matching \\"snapshot_escape_substitution.test.js\\".
Ran all test suites matching /snapshot_escape_substitution.test.js/i.
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Stack Trace does not print a stack trace for errors when --noStackTrace
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"test_error.test.js\\".
Ran all test suites matching /test_error.test.js/i.
"
`;
Expand All @@ -14,7 +14,7 @@ exports[`Stack Trace does not print a stack trace for matching errors when --noS
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"stack_trace.test.js\\".
Ran all test suites matching /stack_trace.test.js/i.
"
`;
Expand All @@ -23,7 +23,7 @@ exports[`Stack Trace does not print a stack trace for runtime errors when --noSt
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"runtime_error.test.js\\".
Ran all test suites matching /runtime_error.test.js/i.
"
`;
Expand All @@ -32,7 +32,7 @@ exports[`Stack Trace prints a stack trace for errors 1`] = `
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"test_error.test.js\\".
Ran all test suites matching /test_error.test.js/i.
"
`;
Expand All @@ -41,7 +41,7 @@ exports[`Stack Trace prints a stack trace for errors without message in stack tr
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"stack_trace_without_message.test.js\\".
Ran all test suites matching /stack_trace_without_message.test.js/i.
"
`;
Expand All @@ -50,7 +50,7 @@ exports[`Stack Trace prints a stack trace for matching errors 1`] = `
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"stack_trace.test.js\\".
Ran all test suites matching /stack_trace.test.js/i.
"
`;
Expand All @@ -59,6 +59,6 @@ exports[`Stack Trace prints a stack trace for runtime errors 1`] = `
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching \\"runtime_error.test.js\\".
Ran all test suites matching /runtime_error.test.js/i.
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ test('prints a message with path pattern at the end', () => {
let stderr;

({stderr} = runJest(DIR, ['a']));
expect(stderr).toMatch('Ran all test suites matching "a"');
expect(stderr).toMatch('Ran all test suites matching /a/i');

({stderr} = runJest(DIR, ['a', 'b']));
expect(stderr).toMatch('Ran all test suites matching /a|b/');
expect(stderr).toMatch('Ran all test suites matching /a|b/i');

({stderr} = runJest(DIR, ['--testPathPattern', 'a']));
expect(stderr).toMatch('Ran all test suites matching /a/');
expect(stderr).toMatch('Ran all test suites matching /a/i');

({stderr} = runJest(DIR, ['--testPathPattern', 'a|b']));
expect(stderr).toMatch('Ran all test suites matching /a|b/');
expect(stderr).toMatch('Ran all test suites matching /a|b/i');
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Watch mode flows Runs Jest once by default and shows usage 1`] = `
Array [
"
Watch Usage
› Press o to only run tests related to changed files.
› Press a to run all tests.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,3 @@ exports[`Watch mode flows Results in pattern mode get truncated appropriately 2`
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows can select a specific test name from the typeahead results 1`] = `"should convert string to a RegExp"`;
77 changes: 33 additions & 44 deletions packages/jest-cli/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ jest.doMock(
() =>
function() {
const args = Array.from(arguments);
const {onComplete} = args[0];
runJestMock.apply(null, args);

// Call the callback
args[args.length - 1]({snapshot: {}});
onComplete({snapshot: {}});

return Promise.resolve();
},
Expand All @@ -37,7 +38,6 @@ afterEach(runJestMock.mockReset);
describe('Watch mode flows', () => {
let pipe;
let hasteMapInstances;
let argv;
let globalConfig;
let contexts;
let stdin;
Expand All @@ -47,112 +47,101 @@ describe('Watch mode flows', () => {
pipe = {write: jest.fn()};
globalConfig = {watch: true};
hasteMapInstances = [{on: () => {}}];
argv = {};
contexts = [{config}];
stdin = new MockStdin();
});

it('Correctly passing test path pattern', () => {
argv.testPathPattern = 'test-*';
globalConfig.testPathPattern = 'test-*';

watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

expect(runJestMock).toBeCalledWith(
globalConfig,
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
argv,
pipe,
new TestWatcher({isWatchMode: true}),
expect.any(Function),
undefined,
expect.any(Function),
);
globalConfig,
onComplete: expect.any(Function),
outputStream: pipe,
testWatcher: new TestWatcher({isWatchMode: true}),
});
});

it('Correctly passing test name pattern', () => {
argv.testNamePattern = 'test-*';
globalConfig.testNamePattern = 'test-*';

watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

expect(runJestMock).toBeCalledWith(
globalConfig,
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
argv,
pipe,
new TestWatcher({isWatchMode: true}),
expect.any(Function),
undefined,
expect.any(Function),
);
globalConfig,
onComplete: expect.any(Function),
outputStream: pipe,
testWatcher: new TestWatcher({isWatchMode: true}),
});
});

it('Runs Jest once by default and shows usage', () => {
watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
expect(runJestMock).toBeCalledWith(
globalConfig,
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
argv,
pipe,
new TestWatcher({isWatchMode: true}),
expect.any(Function),
undefined,
expect.any(Function),
);
globalConfig,
onComplete: expect.any(Function),
outputStream: pipe,
testWatcher: new TestWatcher({isWatchMode: true}),
});
expect(pipe.write.mock.calls.reverse()[0]).toMatchSnapshot();
});

it('Pressing "o" runs test in "only changed files" mode', () => {
watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
runJestMock.mockReset();

stdin.emit(KEYS.O);

expect(runJestMock).toBeCalled();
expect(argv).toEqual({
expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
onlyChanged: true,
watch: true,
watchAll: false,
});
});

it('Pressing "a" runs test in "watch all" mode', () => {
watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
runJestMock.mockReset();

stdin.emit(KEYS.A);

expect(runJestMock).toBeCalled();
expect(argv).toEqual({
expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
onlyChanged: false,
watch: false,
watchAll: true,
});
});

it('Pressing "ENTER" reruns the tests', () => {
watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock).toHaveBeenCalledTimes(1);
stdin.emit(KEYS.ENTER);
expect(runJestMock).toHaveBeenCalledTimes(2);
});

it('Pressing "u" reruns the tests in "update snapshot" mode', () => {
watch(globalConfig, contexts, argv, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
runJestMock.mockReset();

stdin.emit(KEYS.U);

expect(runJestMock.mock.calls[0][0]).toEqual({
expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
updateSnapshot: 'all',
watch: true,
});

stdin.emit(KEYS.A);
// updateSnapshot is not sticky after a run.
expect(runJestMock.mock.calls[1][0]).toEqual({
watch: true,
expect(runJestMock.mock.calls[1][0].globalConfig).toMatchObject({
updateSnapshot: 'none',
watch: false,
});
});
});
Expand Down
Loading

0 comments on commit 6b28cf2

Please sign in to comment.