Skip to content

Commit 2167439

Browse files
kdnaktcpojer
authored andcommitted
Add summary_reporter.test.js (#5389)
* add special option -- for npm update command * Update CHANGELOG.md * add testcase for summary_reporter.js * add testcase for yarn * Update CHANGELOG.md * import SummaryReporter at the top * remove duplicated definition of results * remove description * add snapshot test * update test title * remove duplicated line * add missing attributes for test results
1 parent 0110101 commit 2167439

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* `[expect]` Support class instances in `.toHaveProperty()` matcher.
1313
([#5367](https://github.com/facebook/jest/pull/5367))
1414
* `[jest-cli]` Fix npm update command for snapshot summary.
15-
([#5376](https://github.com/facebook/jest/pull/5376))
15+
([#5376](https://github.com/facebook/jest/pull/5376),
16+
[5389](https://github.com/facebook/jest/pull/5389/))
1617
* `[expect]` Make `rejects` and `resolves` synchronously validate its argument.
1718
([#5364](https://github.com/facebook/jest/pull/5364))
1819
* `[docs]` Add tutorial page for ES6 class mocks.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`snapshots needs update with npm test 1`] = `
4+
"<bold>Snapshot Summary</>
5+
<bold><red> › 2 snapshot tests</></> failed in 1 test suite. <dim>Inspect your code changes or run \`npm test -- -u\` to update them.</>
6+
7+
<bold>Test Suites: </><bold><red>1 failed</></>, 1 total
8+
<bold>Tests: </><bold><red>1 failed</></>, 1 total
9+
<bold>Snapshots: </><bold><red>2 failed</></>, 2 total
10+
<bold>Time:</> 0.01s
11+
<dim>Ran all test suites</><dim>.</>
12+
"
13+
`;
14+
15+
exports[`snapshots needs update with yarn test 1`] = `
16+
"<bold>Snapshot Summary</>
17+
<bold><red> › 2 snapshot tests</></> failed in 1 test suite. <dim>Inspect your code changes or run \`yarn test -u\` to update them.</>
18+
19+
<bold>Test Suites: </><bold><red>1 failed</></>, 1 total
20+
<bold>Tests: </><bold><red>1 failed</></>, 1 total
21+
<bold>Snapshots: </><bold><red>2 failed</></>, 2 total
22+
<bold>Time:</> 0.01s
23+
<dim>Ran all test suites</><dim>.</>
24+
"
25+
`;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
import SummaryReporter from '../summary_reporter';
10+
11+
const env = Object.assign({}, process.env);
12+
const now = Date.now;
13+
const write = process.stderr.write;
14+
const globalConfig = {
15+
watch: false,
16+
};
17+
const aggregatedResults = {
18+
numFailedTestSuites: 1,
19+
numFailedTests: 1,
20+
numPassedTestSuites: 0,
21+
numTotalTestSuites: 1,
22+
numTotalTests: 1,
23+
snapshot: {
24+
filesUnmatched: 1,
25+
total: 2,
26+
unmatched: 2,
27+
},
28+
startTime: 0,
29+
testResults: {},
30+
};
31+
32+
let results = [];
33+
34+
beforeEach(() => {
35+
process.env.npm_lifecycle_event = 'test';
36+
process.env.npm_lifecycle_script = 'jest';
37+
process.stderr.write = result => results.push(result);
38+
Date.now = () => 10;
39+
});
40+
41+
afterEach(() => {
42+
results = [];
43+
process.env = env;
44+
process.stderr.write = write;
45+
Date.now = now;
46+
});
47+
48+
test('snapshots needs update with npm test', () => {
49+
process.env.npm_config_user_agent = 'npm';
50+
const testReporter = new SummaryReporter(globalConfig);
51+
testReporter.onRunComplete(new Set(), aggregatedResults);
52+
expect(results.join('')).toMatchSnapshot();
53+
});
54+
55+
test('snapshots needs update with yarn test', () => {
56+
process.env.npm_config_user_agent = 'yarn';
57+
const testReporter = new SummaryReporter(globalConfig);
58+
testReporter.onRunComplete(new Set(), aggregatedResults);
59+
expect(results.join('')).toMatchSnapshot();
60+
});

0 commit comments

Comments
 (0)