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

Add summary_reporter.test.js #5389

Merged
merged 15 commits into from
Jan 28, 2018
Merged
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* `[expect]` Support class instances in `.toHaveProperty()` matcher.
([#5367](https://github.com/facebook/jest/pull/5367))
* `[jest-cli]` Fix npm update command for snapshot summary.
([#5376](https://github.com/facebook/jest/pull/5376))
([#5376](https://github.com/facebook/jest/pull/5376),
[5389](https://github.com/facebook/jest/pull/5389/))
* `[expect]` Make `rejects` and `resolves` synchronously validate its argument.
([#5364](https://github.com/facebook/jest/pull/5364))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshots needs update with npm test 1`] = `
"<bold>Snapshot Summary</>
<bold><red> › 2 snapshot tests</></> failed in 1 test suite. <dim>Inspect your code changes or run \`npm test -- -u\` to update them.</>

<bold>Test Suites: </><bold><red>1 failed</></>, 1 total
<bold>Tests: </><bold><red>1 failed</></>, 1 total
<bold>Snapshots: </><bold><red>2 failed</></>, 2 total
<bold>Time:</> 0.01s
<dim>Ran all test suites</><dim>.</>
"
`;

exports[`snapshots needs update with yarn test 1`] = `
"<bold>Snapshot Summary</>
<bold><red> › 2 snapshot tests</></> failed in 1 test suite. <dim>Inspect your code changes or run \`yarn test -u\` to update them.</>

<bold>Test Suites: </><bold><red>1 failed</></>, 1 total
<bold>Tests: </><bold><red>1 failed</></>, 1 total
<bold>Snapshots: </><bold><red>2 failed</></>, 2 total
<bold>Time:</> 0.01s
<dim>Ran all test suites</><dim>.</>
"
`;
60 changes: 60 additions & 0 deletions packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forgot about adding @flow pragma here. See how it's done in other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding @flow made the test fail ...

 39:   process.stderr.write = result => results.push(result);
                      ^^^^^ property `write`. Covariant property `write` incompatible with contravariant use in

And other *.test.js files also don't have @flow pragma. So is it possible to skip adding it here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, forgot we only added it to integration tests. Cool, we can skip it for now.

'use strict';

import SummaryReporter from '../summary_reporter';

const env = Object.assign({}, process.env);
const now = Date.now;
const write = process.stderr.write;
const globalConfig = {
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 = [];

beforeEach(() => {
process.env.npm_lifecycle_event = 'test';
process.env.npm_lifecycle_script = 'jest';
process.stderr.write = result => results.push(result);
Date.now = () => 10;
});

afterEach(() => {
results = [];
process.env = env;
process.stderr.write = write;
Date.now = now;
});

test('snapshots needs update with npm test', () => {
process.env.npm_config_user_agent = 'npm';
const testReporter = new SummaryReporter(globalConfig);
testReporter.onRunComplete(new Set(), aggregatedResults);
expect(results.join('')).toMatchSnapshot();
});

test('snapshots needs update with yarn test', () => {
process.env.npm_config_user_agent = 'yarn';
const testReporter = new SummaryReporter(globalConfig);
testReporter.onRunComplete(new Set(), aggregatedResults);
expect(results.join('')).toMatchSnapshot();
});