From 2086510a8238254f122a7c6da08326c81150ae92 Mon Sep 17 00:00:00 2001 From: rickhanlonii Date: Sun, 13 May 2018 17:31:15 -0400 Subject: [PATCH 1/4] Better snapshot summary reports --- .../__snapshots__/failures.test.js.snap | 6 +- .../__snapshots__/snapshot.test.js.snap | 28 ++-- integration-tests/__tests__/snapshot.test.js | 26 ++-- .../__tests__/to_match_snapshot.test.js | 14 +- .../to_throw_error_matching_snapshot.test.js | 6 +- .../get_snapshot_status.test.js.snap | 24 ++-- .../get_snapshot_summary.test.js.snap | 50 +++++--- .../summary_reporter.test.js.snap | 48 ++++++- .../__tests__/get_snapshot_summary.test.js | 43 ++++++- .../__tests__/summary_reporter.test.js | 120 ++++++++++++++++-- .../src/reporters/get_snapshot_status.js | 49 ++++--- .../src/reporters/get_snapshot_summary.js | 112 +++++++++++----- .../src/reporters/summary_reporter.js | 6 +- packages/jest-cli/src/reporters/utils.js | 23 +++- packages/jest-cli/src/test_result_helpers.js | 15 ++- types/TestResult.js | 7 +- 16 files changed, 431 insertions(+), 146 deletions(-) diff --git a/integration-tests/__tests__/__snapshots__/failures.test.js.snap b/integration-tests/__tests__/__snapshots__/failures.test.js.snap index 9b5b4fd184e7..4c6607125872 100644 --- a/integration-tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/failures.test.js.snap @@ -419,7 +419,8 @@ exports[`works with named snapshot failures 1`] = ` at __tests__/snapshot_named.test.js:12:17 - › 1 snapshot test failed. + › 1 snapshot failed. + " `; @@ -852,6 +853,7 @@ exports[`works with snapshot failures 1`] = ` at __tests__/snapshot.test.js:12:17 - › 1 snapshot test failed. + › 1 snapshot failed. + " `; diff --git a/integration-tests/__tests__/__snapshots__/snapshot.test.js.snap b/integration-tests/__tests__/__snapshots__/snapshot.test.js.snap index 3c664c142b31..7d07b4330396 100644 --- a/integration-tests/__tests__/__snapshots__/snapshot.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/snapshot.test.js.snap @@ -3,7 +3,7 @@ exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 1`] = ` "Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total -Snapshots: 9 added, 9 total +Snapshots: 9 written, 9 total Time: <> Ran all test suites." `; @@ -11,7 +11,7 @@ Ran all test suites." exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 2`] = ` "Test Suites: 3 passed, 3 total Tests: 6 passed, 6 total -Snapshots: 5 passed, 5 total +Snapshots: 1 file removed, 5 passed, 5 total Time: <> Ran all test suites." `; @@ -19,7 +19,7 @@ Ran all test suites." exports[`Snapshot Validation deletes the snapshot if the test suite has been removed 1`] = ` "Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total -Snapshots: 9 added, 9 total +Snapshots: 9 written, 9 total Time: <> Ran all test suites." `; @@ -27,7 +27,7 @@ Ran all test suites." exports[`Snapshot Validation deletes the snapshot if the test suite has been removed 2`] = ` "Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total -Snapshots: 5 passed, 5 total +Snapshots: 1 file removed, 5 passed, 5 total Time: <> Ran all test suites." `; @@ -44,7 +44,7 @@ Ran all test suites. exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 1`] = ` "Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total -Snapshots: 9 added, 9 total +Snapshots: 9 written, 9 total Time: <> Ran all test suites." `; @@ -52,7 +52,7 @@ Ran all test suites." exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 2`] = ` "Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total -Snapshots: 1 updated, 7 passed, 8 total +Snapshots: 1 removed, 1 updated, 7 passed, 8 total Time: <> Ran all test suites." `; @@ -60,7 +60,7 @@ Ran all test suites." exports[`Snapshot Validation works on subsequent runs without \`-u\` 1`] = ` "Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total -Snapshots: 9 added, 9 total +Snapshots: 9 written, 9 total Time: <> Ran all test suites." `; @@ -76,7 +76,7 @@ Ran all test suites." exports[`Snapshot stores new snapshots on the first run 1`] = ` "Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total -Snapshots: 5 added, 5 total +Snapshots: 5 written, 5 total Time: <> Ran all test suites." `; @@ -84,7 +84,7 @@ Ran all test suites." exports[`Snapshot works with escaped characters 1`] = ` "Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total -Snapshots: 1 added, 1 total +Snapshots: 1 written, 1 total Time: <> Ran all test suites matching /snapshot.test.js/i." `; @@ -92,7 +92,7 @@ Ran all test suites matching /snapshot.test.js/i." exports[`Snapshot works with escaped characters 2`] = ` "Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total -Snapshots: 1 added, 1 passed, 2 total +Snapshots: 1 written, 1 passed, 2 total Time: <> Ran all test suites matching /snapshot.test.js/i." `; @@ -108,7 +108,7 @@ Ran all test suites matching /snapshot.test.js/i." exports[`Snapshot works with escaped regex 1`] = ` "Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total -Snapshots: 2 added, 2 total +Snapshots: 2 written, 2 total Time: <> Ran all test suites matching /snapshot_escape_regex.js/i." `; @@ -121,15 +121,15 @@ Time: <> Ran all test suites matching /snapshot_escape_regex.js/i." `; -exports[`Snapshot works with template literal subsitutions 1`] = ` +exports[`Snapshot works with template literal substitutions 1`] = ` "Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total -Snapshots: 1 added, 1 total +Snapshots: 1 written, 1 total Time: <> Ran all test suites matching /snapshot_escape_substitution.test.js/i." `; -exports[`Snapshot works with template literal subsitutions 2`] = ` +exports[`Snapshot works with template literal substitutions 2`] = ` "Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 passed, 1 total diff --git a/integration-tests/__tests__/snapshot.test.js b/integration-tests/__tests__/snapshot.test.js index 693124883ad0..16c7c16d1837 100644 --- a/integration-tests/__tests__/snapshot.test.js +++ b/integration-tests/__tests__/snapshot.test.js @@ -118,7 +118,7 @@ describe('Snapshot', () => { content['snapshot is not influenced by previous counter 1'], ).not.toBeUndefined(); - expect(result.stderr).toMatch('5 snapshots written in 2 test suites'); + expect(result.stderr).toMatch('5 snapshots written from 2 test suites'); expect(extractSummary(result.stderr).summary).toMatchSnapshot(); }); @@ -177,7 +177,7 @@ describe('Snapshot', () => { ]); let stderr = result.stderr; - expect(stderr).toMatch('2 snapshots written in 1 test suite.'); + expect(stderr).toMatch('2 snapshots written from 1 test suite.'); expect(result.status).toBe(0); expect(extractSummary(stderr).summary).toMatchSnapshot(); @@ -195,7 +195,7 @@ describe('Snapshot', () => { expect(result.status).toBe(0); }); - it('works with template literal subsitutions', () => { + it('works with template literal substitutions', () => { // Write the first snapshot let result = runJest('snapshot-escape', [ '-w=1', @@ -252,7 +252,7 @@ describe('Snapshot', () => { expect(secondRun.json.numTotalTests).toBe(9); expect(secondRun.json.success).toBe(true); - expect(firstRun.stderr).toMatch('9 snapshots written in 3 test suites'); + expect(firstRun.stderr).toMatch('9 snapshots written from 3 test suites'); expect(secondRun.stderr).toMatch('9 passed, 9 total'); expect(extractSummary(firstRun.stderr).summary).toMatchSnapshot(); expect(extractSummary(secondRun.stderr).summary).toMatchSnapshot(); @@ -271,8 +271,10 @@ describe('Snapshot', () => { expect(secondRun.json.numTotalTests).toBe(5); expect(fileExists(snapshotOfCopy)).toBe(false); - expect(firstRun.stderr).toMatch('9 snapshots written in 3 test suites'); - expect(secondRun.stderr).toMatch('1 obsolete snapshot file removed'); + expect(firstRun.stderr).toMatch('9 snapshots written from 3 test suites'); + expect(secondRun.stderr).toMatch( + '1 snapshot file removed from 1 test suite', + ); expect(extractSummary(firstRun.stderr).summary).toMatchSnapshot(); expect(extractSummary(secondRun.stderr).summary).toMatchSnapshot(); }); @@ -288,8 +290,10 @@ describe('Snapshot', () => { expect(secondRun.json.numTotalTests).toBe(6); expect(fileExists(snapshotOfCopy)).toBe(false); - expect(firstRun.stderr).toMatch('9 snapshots written in 3 test suites'); - expect(secondRun.stderr).toMatch('1 obsolete snapshot file removed'); + expect(firstRun.stderr).toMatch('9 snapshots written from 3 test suites'); + expect(secondRun.stderr).toMatch( + '1 snapshot file removed from 1 test suite', + ); expect(extractSummary(firstRun.stderr).summary).toMatchSnapshot(); expect(extractSummary(secondRun.stderr).summary).toMatchSnapshot(); }); @@ -323,10 +327,10 @@ describe('Snapshot', () => { expect(beforeRemovingSnapshot[keyToCheck]).not.toBe(undefined); expect(afterRemovingSnapshot[keyToCheck]).toBe(undefined); - expect(firstRun.stderr).toMatch('9 snapshots written in 3 test suites'); + expect(firstRun.stderr).toMatch('9 snapshots written from 3 test suites'); expect(extractSummary(firstRun.stderr).summary).toMatchSnapshot(); - expect(secondRun.stderr).toMatch('1 snapshot updated in 1 test suite'); - expect(secondRun.stderr).toMatch('1 obsolete snapshot removed'); + expect(secondRun.stderr).toMatch('1 snapshot updated from 1 test suite'); + expect(secondRun.stderr).toMatch('1 snapshot removed from 1 test suite'); expect(extractSummary(secondRun.stderr).summary).toMatchSnapshot(); }); }); diff --git a/integration-tests/__tests__/to_match_snapshot.test.js b/integration-tests/__tests__/to_match_snapshot.test.js index eceb5b79e049..cb4902f83c69 100644 --- a/integration-tests/__tests__/to_match_snapshot.test.js +++ b/integration-tests/__tests__/to_match_snapshot.test.js @@ -28,14 +28,14 @@ test('basic support', () => { [filename]: template(['{apple: "original value"}']), }); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } { const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); - expect(stderr).not.toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).not.toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } @@ -58,7 +58,7 @@ test('basic support', () => { filename, '-u', ]); - expect(stderr).toMatch('1 snapshot updated in 1 test suite.'); + expect(stderr).toMatch('1 snapshot updated from 1 test suite.'); expect(status).toBe(0); } }); @@ -75,7 +75,7 @@ test('error thrown before snapshot', () => { [filename]: template(['true', '{a: "original"}']), }); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } @@ -105,7 +105,7 @@ test('first snapshot fails, second passes', () => { { writeFiles(TESTS_DIR, {[filename]: template([`'apple'`, `'banana'`])}); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('2 snapshots written in 1 test suite.'); + expect(stderr).toMatch('2 snapshots written from 1 test suite.'); expect(status).toBe(0); } @@ -133,7 +133,7 @@ test('does not mark snapshots as obsolete in skipped tests', () => { { writeFiles(TESTS_DIR, {[filename]: template(['test'])}); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } @@ -155,7 +155,7 @@ test('accepts custom snapshot name', () => { { writeFiles(TESTS_DIR, {[filename]: template()}); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } }); diff --git a/integration-tests/__tests__/to_throw_error_matching_snapshot.test.js b/integration-tests/__tests__/to_throw_error_matching_snapshot.test.js index f20daf57be1d..b42312580ecd 100644 --- a/integration-tests/__tests__/to_throw_error_matching_snapshot.test.js +++ b/integration-tests/__tests__/to_throw_error_matching_snapshot.test.js @@ -29,7 +29,7 @@ test('works fine when function throws error', () => { { writeFiles(TESTS_DIR, {[filename]: template()}); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } }); @@ -60,7 +60,7 @@ test('accepts custom snapshot name', () => { { writeFiles(TESTS_DIR, {[filename]: template()}); const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(status).toBe(0); } }); @@ -98,7 +98,7 @@ test('should support rejecting promises', () => { 'utf8', ); - expect(stderr).toMatch('1 snapshot written in 1 test suite.'); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); expect(snapshot).toMatchSnapshot(); expect(status).toBe(0); } diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap index 45a0d0760608..03b8fed6bf44 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap @@ -2,23 +2,23 @@ exports[`Retrieves the snapshot status 1`] = ` Array [ - " › 1 snapshot written.", - " › 1 snapshot updated.", - " › 1 obsolete snapshot found.", - " - test suite with unchecked snapshot", - " › 1 snapshot test failed.", + " › 1 snapshot written.", + " › 1 snapshot updated.", + " › 1 snapshot failed.", + " › 1 snapshot obsolete.", + " • test suite with unchecked snapshot", ] `; exports[`Retrieves the snapshot status after a snapshot update 1`] = ` Array [ - " › 2 snapshots written.", - " › 2 snapshots updated.", - " › 2 obsolete snapshots removed.", - " - first test suite with unchecked snapshot", - " - second test suite with unchecked snapshot", - " › Obsolete snapshot file removed.", - " › 2 snapshot tests failed.", + " › 2 snapshots written.", + " › 2 snapshots updated.", + " › 2 snapshots failed.", + " › 2 snapshots removed.", + " • first test suite with unchecked snapshot", + " • second test suite with unchecked snapshot", + " › snapshot file removed.", ] `; diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap index ceb2aa87d21b..8c6196ecbba5 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap @@ -2,39 +2,51 @@ exports[`creates a snapshot summary 1`] = ` Array [ - "Snapshot Summary", - " › 1 snapshot written in 1 test suite.", - " › 1 snapshot test failed in 1 test suite. Inspect your code changes or press --u to update them.", - " › 1 snapshot updated in 1 test suite.", - " › 1 obsolete snapshot file found, press --u to remove it.", - " › 1 obsolete snapshot found, press --u to remove it.", + " +Snapshot Summary", + " › 1 snapshot written from 1 test suite.", + " › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them.", + " › 1 snapshot updated from 1 test suite.", + " › 1 snapshot file obsolete from 1 test suite. To remove it, press --u.", + " › 1 snapshot obsolete from 1 test suite. To remove it, press --u.", + " ↳ ../path/to/suite_one", + " • unchecked snapshot 1", ] `; exports[`creates a snapshot summary after an update 1`] = ` Array [ - "Snapshot Summary", - " › 1 snapshot written in 1 test suite.", - " › 1 snapshot test failed in 1 test suite. Inspect your code changes or press --u to update them.", - " › 1 snapshot updated in 1 test suite.", - " › 1 obsolete snapshot file removed.", - " › 1 obsolete snapshot removed.", + " +Snapshot Summary", + " › 1 snapshot written from 1 test suite.", + " › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them.", + " › 1 snapshot updated from 1 test suite.", + " › 1 snapshot file removed from 1 test suite.", + " › 1 snapshot removed from 1 test suite.", + " ↳ ../path/to/suite_one", + " • unchecked snapshot 1", ] `; exports[`creates a snapshot summary with multiple snapshot being written/updated 1`] = ` Array [ - "Snapshot Summary", - " › 2 snapshots written in 2 test suites.", - " › 2 snapshot tests failed in 2 test suites. Inspect your code changes or press --u to update them.", - " › 2 snapshots updated in 2 test suites.", - " › 2 obsolete snapshot files found, press --u to remove them..", - " › 2 obsolete snapshots found, press --u to remove them.", + " +Snapshot Summary", + " › 2 snapshots written from 2 test suites.", + " › 2 snapshots failed from 2 test suites. Inspect your code changes or press --u to update them.", + " › 2 snapshots updated from 2 test suites.", + " › 2 snapshot files obsolete from 2 test suites. To remove them all, press --u.", + " › 2 snapshots obsolete from 2 test suites. To remove them all, press --u.", + " ↳ ../path/to/suite_one", + " • unchecked snapshot 1", + " ↳ ../path/to/suite_two", + " • unchecked snapshot 2", ] `; exports[`returns nothing if there are no updates 1`] = ` Array [ - "Snapshot Summary", + " +Snapshot Summary", ] `; diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap index 55fb2f7428f7..240073a1facd 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap @@ -1,8 +1,47 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`snapshots all have results (after update) 1`] = ` +" +Snapshot Summary + › 1 snapshot written from 1 test suite. + › 1 snapshot failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. + › 1 snapshot updated from 1 test suite. + › 1 snapshot file removed from 1 test suite. + › 1 snapshot removed from 1 test suite. + ↳ ../path/to/suite_one + • unchecked snapshot 1 + +Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 1 failed, 1 removed, 1 file removed, 1 updated, 1 written, 2 passed, 2 total +Time: 0.01s +Ran all test suites. +" +`; + +exports[`snapshots all have results (no update) 1`] = ` +" +Snapshot Summary + › 1 snapshot written from 1 test suite. + › 1 snapshot failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. + › 1 snapshot updated from 1 test suite. + › 1 snapshot file obsolete from 1 test suite. To remove it, run \`yarn test -u\`. + › 1 snapshot obsolete from 1 test suite. To remove it, run \`yarn test -u\`. + ↳ ../path/to/suite_one + • unchecked snapshot 1 + +Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 1 failed, 1 obsolete, 1 file obsolete, 1 updated, 1 written, 2 passed, 2 total +Time: 0.01s +Ran all test suites. +" +`; + exports[`snapshots needs update with npm test 1`] = ` -"Snapshot Summary - › 2 snapshot tests failed in 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. +" +Snapshot Summary + › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total @@ -13,8 +52,9 @@ exports[`snapshots needs update with npm test 1`] = ` `; exports[`snapshots needs update with yarn test 1`] = ` -"Snapshot Summary - › 2 snapshot tests failed in 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. +" +Snapshot Summary + › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total diff --git a/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js b/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js index b3d80ee15271..87fb4d5e8651 100644 --- a/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js +++ b/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js @@ -11,6 +11,10 @@ import getSnapshotSummary from '../get_snapshot_summary'; const UPDATE_COMMAND = 'press --u'; +const globalConfig = { + rootDir: 'root', +}; + test('creates a snapshot summary', () => { const snapshots = { added: 1, @@ -22,11 +26,19 @@ test('creates a snapshot summary', () => { matched: 2, total: 2, unchecked: 1, + uncheckedKeysByFile: [ + { + filePath: 'path/to/suite_one', + keys: ['unchecked snapshot 1'], + }, + ], unmatched: 1, updated: 1, }; - expect(getSnapshotSummary(snapshots, UPDATE_COMMAND)).toMatchSnapshot(); + expect( + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + ).toMatchSnapshot(); }); test('creates a snapshot summary after an update', () => { @@ -38,11 +50,19 @@ test('creates a snapshot summary after an update', () => { filesUnmatched: 1, filesUpdated: 1, unchecked: 1, + uncheckedKeysByFile: [ + { + filePath: 'path/to/suite_one', + keys: ['unchecked snapshot 1'], + }, + ], unmatched: 1, updated: 1, }; - expect(getSnapshotSummary(snapshots, UPDATE_COMMAND)).toMatchSnapshot(); + expect( + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + ).toMatchSnapshot(); }); it('creates a snapshot summary with multiple snapshot being written/updated', () => { @@ -54,11 +74,23 @@ it('creates a snapshot summary with multiple snapshot being written/updated', () filesUnmatched: 2, filesUpdated: 2, unchecked: 2, + uncheckedKeysByFile: [ + { + filePath: 'path/to/suite_one', + keys: ['unchecked snapshot 1'], + }, + { + filePath: 'path/to/suite_two', + keys: ['unchecked snapshot 2'], + }, + ], unmatched: 2, updated: 2, }; - expect(getSnapshotSummary(snapshots, UPDATE_COMMAND)).toMatchSnapshot(); + expect( + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + ).toMatchSnapshot(); }); it('returns nothing if there are no updates', () => { @@ -70,8 +102,11 @@ it('returns nothing if there are no updates', () => { filesUnmatched: 0, filesUpdated: 0, unchecked: 0, + uncheckedKeysByFile: [], unmatched: 0, updated: 0, }; - expect(getSnapshotSummary(snapshots, UPDATE_COMMAND)).toMatchSnapshot(); + expect( + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + ).toMatchSnapshot(); }); diff --git a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js index 445815207efd..0b457368108e 100644 --- a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js +++ b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js @@ -12,22 +12,9 @@ const env = Object.assign({}, process.env); const now = Date.now; const write = process.stderr.write; const globalConfig = { + rootDir: 'root', watch: false, }; -const aggregatedResults = { - numFailedTestSuites: 1, - numFailedTests: 1, - numPassedTestSuites: 0, - numTotalTestSuites: 1, - numTotalTests: 1, - snapshot: { - filesUnmatched: 1, - total: 2, - unmatched: 2, - }, - startTime: 0, - testResults: {}, -}; let results = []; @@ -46,6 +33,22 @@ afterEach(() => { }); test('snapshots needs update with npm test', () => { + const aggregatedResults = { + numFailedTestSuites: 1, + numFailedTests: 1, + numPassedTestSuites: 0, + numTotalTestSuites: 1, + numTotalTests: 1, + snapshot: { + filesUnmatched: 1, + total: 2, + uncheckedKeysByFile: [], + unmatched: 2, + }, + startTime: 0, + testResults: {}, + }; + process.env.npm_config_user_agent = 'npm'; const testReporter = new SummaryReporter(globalConfig); testReporter.onRunComplete(new Set(), aggregatedResults); @@ -53,8 +56,97 @@ test('snapshots needs update with npm test', () => { }); test('snapshots needs update with yarn test', () => { + const aggregatedResults = { + numFailedTestSuites: 1, + numFailedTests: 1, + numPassedTestSuites: 0, + numTotalTestSuites: 1, + numTotalTests: 1, + snapshot: { + filesUnmatched: 1, + total: 2, + uncheckedKeysByFile: [], + unmatched: 2, + }, + startTime: 0, + testResults: {}, + }; + process.env.npm_config_user_agent = 'yarn'; const testReporter = new SummaryReporter(globalConfig); testReporter.onRunComplete(new Set(), aggregatedResults); expect(results.join('')).toMatchSnapshot(); }); + +test('snapshots all have results (no update)', () => { + const aggregatedResults = { + numFailedTestSuites: 1, + numFailedTests: 1, + numPassedTestSuites: 0, + numTotalTestSuites: 1, + numTotalTests: 1, + snapshot: { + added: 1, + didUpdate: false, + filesAdded: 1, + filesRemoved: 1, + filesUnmatched: 1, + filesUpdated: 1, + matched: 2, + total: 2, + unchecked: 1, + uncheckedKeysByFile: [ + { + filePath: 'path/to/suite_one', + keys: ['unchecked snapshot 1'], + }, + ], + unmatched: 1, + updated: 1, + }, + startTime: 0, + testResults: {}, + }; + + const testReporter = new SummaryReporter(globalConfig); + testReporter.onRunComplete(new Set(), aggregatedResults); + expect(results.join('')).toMatchSnapshot(); +}); + +test('snapshots all have results (after update)', () => { + const aggregatedResults = { + numFailedTestSuites: 1, + numFailedTests: 1, + numPassedTestSuites: 0, + numTotalTestSuites: 1, + numTotalTests: 1, + snapshot: { + added: 1, + didUpdate: true, + filesAdded: 1, + filesRemoved: 1, + filesUnmatched: 1, + filesUpdated: 1, + matched: 2, + total: 2, + unchecked: 1, + uncheckedKeysByFile: [ + { + filePath: 'path/to/suite_one', + keys: ['unchecked snapshot 1'], + }, + ], + unmatched: 1, + updated: 1, + }, + startTime: 0, + testResults: {}, + }; + + const testReporter = new SummaryReporter(globalConfig); + testReporter.onRunComplete(new Set(), aggregatedResults); + expect(results.join('')).toMatchSnapshot(); +}); + +// TODO: add obsolete snapshots and files +// TODO: add more tests to get_snapshot_summary diff --git a/packages/jest-cli/src/reporters/get_snapshot_status.js b/packages/jest-cli/src/reporters/get_snapshot_status.js index c1ecc7e29386..fe7a9de04bbe 100644 --- a/packages/jest-cli/src/reporters/get_snapshot_status.js +++ b/packages/jest-cli/src/reporters/get_snapshot_status.js @@ -14,10 +14,11 @@ const chalk = require('chalk'); const {pluralize} = require('./utils'); const ARROW = ' \u203A '; +const DOT = ' \u2022 '; const FAIL_COLOR = chalk.bold.red; const SNAPSHOT_ADDED = chalk.bold.green; -const SNAPSHOT_REMOVED = chalk.bold.red; const SNAPSHOT_UPDATED = chalk.bold.green; +const SNAPSHOT_OUTDATED = chalk.bold.yellow; export default ( snapshot: $PropertyType, @@ -27,41 +28,51 @@ export default ( if (snapshot.added) { statuses.push( - SNAPSHOT_ADDED(ARROW + pluralize('snapshot', snapshot.added)) + - ' written.', + SNAPSHOT_ADDED( + ARROW + pluralize('snapshot', snapshot.added) + ' written.', + ), ); } if (snapshot.updated) { statuses.push( - SNAPSHOT_UPDATED(ARROW + pluralize('snapshot', snapshot.updated)) + - ` updated.`, + SNAPSHOT_UPDATED( + ARROW + pluralize('snapshot', snapshot.updated) + ' updated.', + ), ); } - if (snapshot.unchecked) { + if (snapshot.unmatched) { statuses.push( - FAIL_COLOR(ARROW + pluralize('obsolete snapshot', snapshot.unchecked)) + - (afterUpdate ? ' removed' : ' found') + - '.', + FAIL_COLOR( + ARROW + pluralize('snapshot', snapshot.unmatched) + ' failed.', + ), ); + } + + if (snapshot.unchecked) { + if (afterUpdate) { + statuses.push( + SNAPSHOT_UPDATED( + ARROW + pluralize('snapshot', snapshot.unchecked) + ' removed.', + ), + ); + } else { + statuses.push( + SNAPSHOT_OUTDATED( + ARROW + pluralize('snapshot', snapshot.unchecked) + ' obsolete', + ) + '.', + ); + } snapshot.uncheckedKeys.forEach(key => { - statuses.push(FAIL_COLOR(` - ${key}`)); + statuses.push(` ${DOT}${key}`); }); } if (snapshot.fileDeleted) { - statuses.push( - SNAPSHOT_REMOVED(ARROW + 'Obsolete snapshot file') + ` removed.`, - ); + statuses.push(SNAPSHOT_UPDATED(ARROW + 'snapshot file removed.')); } - if (snapshot.unmatched) { - statuses.push( - FAIL_COLOR(ARROW + pluralize('snapshot test', snapshot.unmatched)) + - ' failed.', - ); - } return statuses; }; diff --git a/packages/jest-cli/src/reporters/get_snapshot_summary.js b/packages/jest-cli/src/reporters/get_snapshot_summary.js index 92695db99816..49b546db1522 100644 --- a/packages/jest-cli/src/reporters/get_snapshot_summary.js +++ b/packages/jest-cli/src/reporters/get_snapshot_summary.js @@ -8,36 +8,43 @@ */ import type {SnapshotSummary} from 'types/TestResult'; +import type {GlobalConfig} from 'types/Config'; import chalk from 'chalk'; -import {pluralize} from './utils'; +import {formatTestPath, pluralize} from './utils'; const ARROW = ' \u203A '; +const DOWN_ARROW = ' \u21B3 '; +const DOT = ' \u2022 '; const FAIL_COLOR = chalk.bold.red; +const OBSOLETE_COLOR = chalk.bold.yellow; const SNAPSHOT_ADDED = chalk.bold.green; const SNAPSHOT_NOTE = chalk.dim; -const SNAPSHOT_REMOVED = chalk.bold.red; +const SNAPSHOT_REMOVED = chalk.bold.green; const SNAPSHOT_SUMMARY = chalk.bold; const SNAPSHOT_UPDATED = chalk.bold.green; export default ( snapshots: SnapshotSummary, + globalConfig: GlobalConfig, updateCommand: string, ): Array => { const summary = []; summary.push(SNAPSHOT_SUMMARY('Snapshot Summary')); if (snapshots.added) { summary.push( - SNAPSHOT_ADDED(ARROW + pluralize('snapshot', snapshots.added)) + - ` written in ${pluralize('test suite', snapshots.filesAdded)}.`, + SNAPSHOT_ADDED( + ARROW + pluralize('snapshot', snapshots.added) + ' written ', + ) + `from ${pluralize('test suite', snapshots.filesAdded)}.`, ); } if (snapshots.unmatched) { summary.push( - FAIL_COLOR(ARROW + pluralize('snapshot test', snapshots.unmatched)) + - ` failed in ` + - `${pluralize('test suite', snapshots.filesUnmatched)}. ` + + FAIL_COLOR( + `${ARROW}${pluralize('snapshot', snapshots.unmatched)} failed`, + ) + + ` from ${pluralize('test suite', snapshots.filesUnmatched)}. ` + SNAPSHOT_NOTE( 'Inspect your code changes or ' + updateCommand + ' to update them.', ), @@ -46,37 +53,80 @@ export default ( if (snapshots.updated) { summary.push( - SNAPSHOT_UPDATED(ARROW + pluralize('snapshot', snapshots.updated)) + - ` updated in ${pluralize('test suite', snapshots.filesUpdated)}.`, + SNAPSHOT_UPDATED( + ARROW + pluralize('snapshot', snapshots.updated) + ' updated ', + ) + `from ${pluralize('test suite', snapshots.filesUpdated)}.`, ); } if (snapshots.filesRemoved) { - summary.push( - SNAPSHOT_REMOVED( - ARROW + pluralize('obsolete snapshot file', snapshots.filesRemoved), - ) + - (snapshots.didUpdate - ? ' removed.' - : ' found, ' + - updateCommand + - ' to remove ' + - (snapshots.filesRemoved === 1 ? 'it' : 'them.') + - '.'), - ); + if (snapshots.didUpdate) { + summary.push( + SNAPSHOT_REMOVED( + `${ARROW}${pluralize( + 'snapshot file', + snapshots.filesRemoved, + )} removed `, + ) + `from ${pluralize('test suite', snapshots.filesRemoved)}.`, + ); + } else { + summary.push( + OBSOLETE_COLOR( + `${ARROW}${pluralize( + 'snapshot file', + snapshots.filesRemoved, + )} obsolete `, + ) + + `from ${pluralize('test suite', snapshots.filesRemoved)}. ` + + SNAPSHOT_NOTE( + `To remove ${ + snapshots.filesRemoved === 1 ? 'it' : 'them all' + }, ${updateCommand}.`, + ), + ); + } } if (snapshots.unchecked) { - summary.push( - FAIL_COLOR(ARROW + pluralize('obsolete snapshot', snapshots.unchecked)) + - (snapshots.didUpdate - ? ' removed.' - : ' found, ' + - updateCommand + - ' to remove ' + - (snapshots.filesRemoved === 1 ? 'it' : 'them') + - '.'), - ); + if (snapshots.didUpdate) { + summary.push( + SNAPSHOT_REMOVED( + `${ARROW}${pluralize('snapshot', snapshots.unchecked)} removed `, + ) + + `from ${pluralize( + 'test suite', + snapshots.uncheckedKeysByFile.length, + )}.`, + ); + } else { + summary.push( + OBSOLETE_COLOR( + `${ARROW}${pluralize('snapshot', snapshots.unchecked)} obsolete `, + ) + + `from ${pluralize( + 'test suite', + snapshots.uncheckedKeysByFile.length, + )}. ` + + SNAPSHOT_NOTE( + `To remove ${ + snapshots.unchecked === 1 ? 'it' : 'them all' + }, ${updateCommand}.`, + ), + ); + } + + snapshots.uncheckedKeysByFile.forEach(uncheckedFile => { + summary.push( + ` ${DOWN_ARROW}${formatTestPath( + globalConfig, + uncheckedFile.filePath, + )}`, + ); + + uncheckedFile.keys.forEach(key => { + summary.push(` ${DOT}${key}`); + }); + }); } return summary; diff --git a/packages/jest-cli/src/reporters/summary_reporter.js b/packages/jest-cli/src/reporters/summary_reporter.js index 2cadb37eed43..1aecaa7bf766 100644 --- a/packages/jest-cli/src/reporters/summary_reporter.js +++ b/packages/jest-cli/src/reporters/summary_reporter.js @@ -149,7 +149,11 @@ export default class SummaryReporter extends BaseReporter { updateCommand = 're-run jest with `-u`'; } - const snapshotSummary = getSnapshotSummary(snapshots, updateCommand); + const snapshotSummary = getSnapshotSummary( + snapshots, + globalConfig, + updateCommand, + ); snapshotSummary.forEach(this.log); this.log(''); // print empty line diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-cli/src/reporters/utils.js index 2fe08ec2e973..67b2d776fdab 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-cli/src/reporters/utils.js @@ -108,6 +108,9 @@ export const getSummary = ( const snapshotResults = aggregatedResults.snapshot; const snapshotsAdded = snapshotResults.added; const snapshotsFailed = snapshotResults.unmatched; + const snapshotsOutdated = snapshotResults.unchecked; + const snapshotsFilesRemoved = snapshotResults.filesRemoved; + const snapshotsDidUpdate = snapshotResults.didUpdate; const snapshotsPassed = snapshotResults.matched; const snapshotsTotal = snapshotResults.total; const snapshotsUpdated = snapshotResults.updated; @@ -146,10 +149,28 @@ export const getSummary = ( (snapshotsFailed ? chalk.bold.red(`${snapshotsFailed} failed`) + ', ' : '') + + (snapshotsOutdated && !snapshotsDidUpdate + ? chalk.bold.yellow(`${snapshotsOutdated} obsolete`) + ', ' + : '') + + (snapshotsOutdated && snapshotsDidUpdate + ? chalk.bold.green(`${snapshotsOutdated} removed`) + ', ' + : '') + + (snapshotsFilesRemoved && !snapshotsDidUpdate + ? chalk.bold.yellow( + pluralize('file', snapshotsFilesRemoved) + ' obsolete', + ) + ', ' + : '') + + (snapshotsFilesRemoved && snapshotsDidUpdate + ? chalk.bold.green( + pluralize('file', snapshotsFilesRemoved) + ' removed', + ) + ', ' + : '') + (snapshotsUpdated ? chalk.bold.green(`${snapshotsUpdated} updated`) + ', ' : '') + - (snapshotsAdded ? chalk.bold.green(`${snapshotsAdded} added`) + ', ' : '') + + (snapshotsAdded + ? chalk.bold.green(`${snapshotsAdded} written`) + ', ' + : '') + (snapshotsPassed ? chalk.bold.green(`${snapshotsPassed} passed`) + ', ' : '') + diff --git a/packages/jest-cli/src/test_result_helpers.js b/packages/jest-cli/src/test_result_helpers.js index a10bc5acf39f..14d9d15fd031 100644 --- a/packages/jest-cli/src/test_result_helpers.js +++ b/packages/jest-cli/src/test_result_helpers.js @@ -37,7 +37,7 @@ export const makeEmptyAggregatedTestResult = (): AggregatedResult => { matched: 0, total: 0, unchecked: 0, - uncheckedKeys: [], + uncheckedKeysByFile: [], unmatched: 0, updated: 0, }, @@ -71,7 +71,7 @@ export const buildFailureTestResult = ( fileDeleted: false, matched: 0, unchecked: 0, - uncheckedKeys: [], + uncheckedKeysByFile: [], unmatched: 0, updated: 0, }, @@ -125,7 +125,16 @@ export const addResult = ( aggregatedResults.snapshot.added += testResult.snapshot.added; aggregatedResults.snapshot.matched += testResult.snapshot.matched; aggregatedResults.snapshot.unchecked += testResult.snapshot.unchecked; - aggregatedResults.snapshot.uncheckedKeys = testResult.snapshot.uncheckedKeys; + if ( + testResult.snapshot.uncheckedKeys && + testResult.snapshot.uncheckedKeys.length > 0 + ) { + aggregatedResults.snapshot.uncheckedKeysByFile.push({ + filePath: testResult.testFilePath, + keys: testResult.snapshot.uncheckedKeys, + }); + } + aggregatedResults.snapshot.unmatched += testResult.snapshot.unmatched; aggregatedResults.snapshot.updated += testResult.snapshot.updated; aggregatedResults.snapshot.total += diff --git a/types/TestResult.js b/types/TestResult.js index 46cebb44fcc6..d58a61c4ca37 100644 --- a/types/TestResult.js +++ b/types/TestResult.js @@ -207,6 +207,11 @@ export type CodeCoverageFormatter = ( reporter?: CodeCoverageReporter, ) => ?Object; +export type UncheckedSnapshot = {| + filePath: string, + keys: Array, +|}; + export type SnapshotSummary = {| added: number, didUpdate: boolean, @@ -218,7 +223,7 @@ export type SnapshotSummary = {| matched: number, total: number, unchecked: number, - uncheckedKeys: Array, + uncheckedKeysByFile: Array, unmatched: number, updated: number, |}; From 92633357eb0cf6af054782ca67055989c5e89a34 Mon Sep 17 00:00:00 2001 From: rickhanlonii Date: Sun, 13 May 2018 17:40:02 -0400 Subject: [PATCH 2/4] Fix flow and remove extra newline --- .../__tests__/__snapshots__/failures.test.js.snap | 2 -- .../__snapshots__/get_snapshot_summary.test.js.snap | 12 ++++-------- .../__snapshots__/summary_reporter.test.js.snap | 12 ++++-------- packages/jest-cli/src/test_result_helpers.js | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/integration-tests/__tests__/__snapshots__/failures.test.js.snap b/integration-tests/__tests__/__snapshots__/failures.test.js.snap index 4c6607125872..71f812b05534 100644 --- a/integration-tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/failures.test.js.snap @@ -420,7 +420,6 @@ exports[`works with named snapshot failures 1`] = ` at __tests__/snapshot_named.test.js:12:17 › 1 snapshot failed. - " `; @@ -854,6 +853,5 @@ exports[`works with snapshot failures 1`] = ` at __tests__/snapshot.test.js:12:17 › 1 snapshot failed. - " `; diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap index 8c6196ecbba5..73cc0520bd65 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap @@ -2,8 +2,7 @@ exports[`creates a snapshot summary 1`] = ` Array [ - " -Snapshot Summary", + "Snapshot Summary", " › 1 snapshot written from 1 test suite.", " › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them.", " › 1 snapshot updated from 1 test suite.", @@ -16,8 +15,7 @@ Array [ exports[`creates a snapshot summary after an update 1`] = ` Array [ - " -Snapshot Summary", + "Snapshot Summary", " › 1 snapshot written from 1 test suite.", " › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them.", " › 1 snapshot updated from 1 test suite.", @@ -30,8 +28,7 @@ Array [ exports[`creates a snapshot summary with multiple snapshot being written/updated 1`] = ` Array [ - " -Snapshot Summary", + "Snapshot Summary", " › 2 snapshots written from 2 test suites.", " › 2 snapshots failed from 2 test suites. Inspect your code changes or press --u to update them.", " › 2 snapshots updated from 2 test suites.", @@ -46,7 +43,6 @@ Array [ exports[`returns nothing if there are no updates 1`] = ` Array [ - " -Snapshot Summary", + "Snapshot Summary", ] `; diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap index 240073a1facd..81cc12f595a4 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`snapshots all have results (after update) 1`] = ` -" -Snapshot Summary +"Snapshot Summary › 1 snapshot written from 1 test suite. › 1 snapshot failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. › 1 snapshot updated from 1 test suite. @@ -20,8 +19,7 @@ exports[`snapshots all have results (after update) 1`] = ` `; exports[`snapshots all have results (no update) 1`] = ` -" -Snapshot Summary +"Snapshot Summary › 1 snapshot written from 1 test suite. › 1 snapshot failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. › 1 snapshot updated from 1 test suite. @@ -39,8 +37,7 @@ exports[`snapshots all have results (no update) 1`] = ` `; exports[`snapshots needs update with npm test 1`] = ` -" -Snapshot Summary +"Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. Test Suites: 1 failed, 1 total @@ -52,8 +49,7 @@ exports[`snapshots needs update with npm test 1`] = ` `; exports[`snapshots needs update with yarn test 1`] = ` -" -Snapshot Summary +"Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. Test Suites: 1 failed, 1 total diff --git a/packages/jest-cli/src/test_result_helpers.js b/packages/jest-cli/src/test_result_helpers.js index 14d9d15fd031..5cd605481eff 100644 --- a/packages/jest-cli/src/test_result_helpers.js +++ b/packages/jest-cli/src/test_result_helpers.js @@ -71,7 +71,7 @@ export const buildFailureTestResult = ( fileDeleted: false, matched: 0, unchecked: 0, - uncheckedKeysByFile: [], + uncheckedKeys: [], unmatched: 0, updated: 0, }, From eefa4e871eb2447a4efbeb95e3ea8c11542540b8 Mon Sep 17 00:00:00 2001 From: rickhanlonii Date: Mon, 14 May 2018 21:38:03 -0400 Subject: [PATCH 3/4] Fix windows? --- .../get_snapshot_summary.test.js.snap | 58 +++++++++---------- .../__tests__/get_snapshot_summary.test.js | 14 +++-- .../__tests__/summary_reporter.test.js | 4 +- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap index 73cc0520bd65..427208ce691a 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap @@ -1,44 +1,38 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`creates a snapshot summary 1`] = ` -Array [ - "Snapshot Summary", - " › 1 snapshot written from 1 test suite.", - " › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them.", - " › 1 snapshot updated from 1 test suite.", - " › 1 snapshot file obsolete from 1 test suite. To remove it, press --u.", - " › 1 snapshot obsolete from 1 test suite. To remove it, press --u.", - " ↳ ../path/to/suite_one", - " • unchecked snapshot 1", -] +"Snapshot Summary + › 1 snapshot written from 1 test suite. + › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them. + › 1 snapshot updated from 1 test suite. + › 1 snapshot file obsolete from 1 test suite. To remove it, press --u. + › 1 snapshot obsolete from 1 test suite. To remove it, press --u. + ↳ ../path/to/suite_one + • unchecked snapshot 1" `; exports[`creates a snapshot summary after an update 1`] = ` -Array [ - "Snapshot Summary", - " › 1 snapshot written from 1 test suite.", - " › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them.", - " › 1 snapshot updated from 1 test suite.", - " › 1 snapshot file removed from 1 test suite.", - " › 1 snapshot removed from 1 test suite.", - " ↳ ../path/to/suite_one", - " • unchecked snapshot 1", -] +"Snapshot Summary + › 1 snapshot written from 1 test suite. + › 1 snapshot failed from 1 test suite. Inspect your code changes or press --u to update them. + › 1 snapshot updated from 1 test suite. + › 1 snapshot file removed from 1 test suite. + › 1 snapshot removed from 1 test suite. + ↳ ../path/to/suite_one + • unchecked snapshot 1" `; exports[`creates a snapshot summary with multiple snapshot being written/updated 1`] = ` -Array [ - "Snapshot Summary", - " › 2 snapshots written from 2 test suites.", - " › 2 snapshots failed from 2 test suites. Inspect your code changes or press --u to update them.", - " › 2 snapshots updated from 2 test suites.", - " › 2 snapshot files obsolete from 2 test suites. To remove them all, press --u.", - " › 2 snapshots obsolete from 2 test suites. To remove them all, press --u.", - " ↳ ../path/to/suite_one", - " • unchecked snapshot 1", - " ↳ ../path/to/suite_two", - " • unchecked snapshot 2", -] +"Snapshot Summary + › 2 snapshots written from 2 test suites. + › 2 snapshots failed from 2 test suites. Inspect your code changes or press --u to update them. + › 2 snapshots updated from 2 test suites. + › 2 snapshot files obsolete from 2 test suites. To remove them all, press --u. + › 2 snapshots obsolete from 2 test suites. To remove them all, press --u. + ↳ ../path/to/suite_one + • unchecked snapshot 1 + ↳ ../path/to/suite_two + • unchecked snapshot 2" `; exports[`returns nothing if there are no updates 1`] = ` diff --git a/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js b/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js index 87fb4d5e8651..bfcbb8d58cd5 100644 --- a/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js +++ b/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js @@ -37,7 +37,9 @@ test('creates a snapshot summary', () => { }; expect( - getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND) + .join('\n') + .replace(/\\/g, '/'), ).toMatchSnapshot(); }); @@ -61,7 +63,9 @@ test('creates a snapshot summary after an update', () => { }; expect( - getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND) + .join('\n') + .replace(/\\/g, '/'), ).toMatchSnapshot(); }); @@ -89,7 +93,9 @@ it('creates a snapshot summary with multiple snapshot being written/updated', () }; expect( - getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND) + .join('\n') + .replace(/\\/g, '/'), ).toMatchSnapshot(); }); @@ -107,6 +113,6 @@ it('returns nothing if there are no updates', () => { updated: 0, }; expect( - getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND), + getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND).join('\n'), ).toMatchSnapshot(); }); diff --git a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js index 0b457368108e..70b507645602 100644 --- a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js +++ b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js @@ -110,7 +110,7 @@ test('snapshots all have results (no update)', () => { const testReporter = new SummaryReporter(globalConfig); testReporter.onRunComplete(new Set(), aggregatedResults); - expect(results.join('')).toMatchSnapshot(); + expect(results.join('').replace(/\\/g, '/')).toMatchSnapshot(); }); test('snapshots all have results (after update)', () => { @@ -145,7 +145,7 @@ test('snapshots all have results (after update)', () => { const testReporter = new SummaryReporter(globalConfig); testReporter.onRunComplete(new Set(), aggregatedResults); - expect(results.join('')).toMatchSnapshot(); + expect(results.join('').replace(/\\/g, '/')).toMatchSnapshot(); }); // TODO: add obsolete snapshots and files From 3464dcef6ad3fc867a20c56ccf5f66071a2afa20 Mon Sep 17 00:00:00 2001 From: rickhanlonii Date: Mon, 14 May 2018 23:21:25 -0400 Subject: [PATCH 4/4] Update snaps --- .../__snapshots__/get_snapshot_summary.test.js.snap | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap index 427208ce691a..6872f4949453 100644 --- a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap @@ -35,8 +35,4 @@ exports[`creates a snapshot summary with multiple snapshot being written/updated • unchecked snapshot 2" `; -exports[`returns nothing if there are no updates 1`] = ` -Array [ - "Snapshot Summary", -] -`; +exports[`returns nothing if there are no updates 1`] = `"Snapshot Summary"`;