Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better snapshot summaries #6181

Merged
merged 4 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ exports[`works with named snapshot failures 1`] = `

at __tests__/snapshot_named.test.js:12:17

› 1 snapshot test failed.
› 1 snapshot failed.
"
`;

Expand Down Expand Up @@ -852,6 +852,6 @@ exports[`works with snapshot failures 1`] = `

at __tests__/snapshot.test.js:12:17

› 1 snapshot test failed.
› 1 snapshot failed.
"
`;
28 changes: 14 additions & 14 deletions integration-tests/__tests__/__snapshots__/snapshot.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
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: <<REPLACED>>
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: <<REPLACED>>
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: <<REPLACED>>
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: <<REPLACED>>
Ran all test suites."
`;
Expand All @@ -44,23 +44,23 @@ 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: <<REPLACED>>
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: <<REPLACED>>
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: <<REPLACED>>
Ran all test suites."
`;
Expand All @@ -76,23 +76,23 @@ 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: <<REPLACED>>
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: <<REPLACED>>
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: <<REPLACED>>
Ran all test suites matching /snapshot.test.js/i."
`;
Expand All @@ -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: <<REPLACED>>
Ran all test suites matching /snapshot_escape_regex.js/i."
`;
Expand All @@ -121,15 +121,15 @@ Time: <<REPLACED>>
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: <<REPLACED>>
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
Expand Down
26 changes: 15 additions & 11 deletions integration-tests/__tests__/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -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();

Expand All @@ -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',
Expand Down Expand Up @@ -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();
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
});
});
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/__tests__/to_match_snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
});
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

exports[`Retrieves the snapshot status 1`] = `
Array [
"<bold><green> › 1 snapshot</></> written.",
"<bold><green> › 1 snapshot</></> updated.",
"<bold><red> › 1 obsolete snapshot</></> found.",
"<bold><red> - test suite with unchecked snapshot</></>",
"<bold><red> › 1 snapshot test</></> failed.",
"<bold><green> › 1 snapshot written.</></>",
"<bold><green> › 1 snapshot updated.</></>",
"<bold><red> › 1 snapshot failed.</></>",
"<bold><yellow> › 1 snapshot obsolete</></>.",
" test suite with unchecked snapshot",
]
`;

exports[`Retrieves the snapshot status after a snapshot update 1`] = `
Array [
"<bold><green> › 2 snapshots</></> written.",
"<bold><green> › 2 snapshots</></> updated.",
"<bold><red> › 2 obsolete snapshots</></> removed.",
"<bold><red> - first test suite with unchecked snapshot</></>",
"<bold><red> - second test suite with unchecked snapshot</></>",
"<bold><red> › Obsolete snapshot file</></> removed.",
"<bold><red> › 2 snapshot tests</></> failed.",
"<bold><green> › 2 snapshots written.</></>",
"<bold><green> › 2 snapshots updated.</></>",
"<bold><red> › 2 snapshots failed.</></>",
"<bold><green> › 2 snapshots removed.</></>",
" • first test suite with unchecked snapshot",
" • second test suite with unchecked snapshot",
"<bold><green> › snapshot file removed.</></>",
]
`;

Expand Down
Loading