Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
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
63 changes: 63 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,63 @@
/**
* 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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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';

const env = Object.assign({}, process.env);
const write = process.stderr.write;
const globalConfig = {
watch: false,
};
const aggregatedResults = {
numTotalTestSuites: 1,
snapshot: {
filesUnmatched: 1,
unmatched: 2,
},
testResults: {},
};

let results = [];
let SummaryReporter;

beforeEach(() => {
process.env.npm_lifecycle_event = 'test';
process.env.npm_lifecycle_script = 'jest';
process.stderr.write = result => results.push(result);
SummaryReporter = require('../summary_reporter').default;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can import SummaryReporter at the top of the file

});

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

describe('onRunComplete', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove the describe and just move its title to the tests? There's too little going on here to benefit from using it

test('npm test', () => {
process.env.npm_config_user_agent = 'npm';
const results = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Results are already defined, no need to shadow it

process.stderr.write = result => results.push(result);
const testReporter = new SummaryReporter(globalConfig);
testReporter.onRunComplete(new Set(), aggregatedResults);
expect(results[0]).toMatch('\u001b[1mSnapshot Summary\u001b[22m');
expect(results[1]).toMatch(
'\u001b[1m\u001b[31m › 2 snapshot tests\u001b[39m\u001b[22m failed in 1 test suite. ' +
'\u001b[2mInspect your code changes or run `npm test -- -u` to update them.\u001b[22m',
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we join results with \n and store it as a snapshot? Or at least strip ansi. Same for the other test

});

test('yarn test', () => {
process.env.npm_config_user_agent = 'yarn';
const testReporter = new SummaryReporter(globalConfig);
testReporter.onRunComplete(new Set(), aggregatedResults);
expect(results[0]).toMatch('\u001b[1mSnapshot Summary\u001b[22m');
expect(results[1]).toMatch(
'\u001b[1m\u001b[31m › 2 snapshot tests\u001b[39m\u001b[22m failed in 1 test suite. ' +
'\u001b[2mInspect your code changes or run `yarn test -u` to update them.\u001b[22m',
);
});
});