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

Conversation

kdnakt
Copy link
Contributor

@kdnakt kdnakt commented Jan 24, 2018

Summary

I just added summary_reporter.test.js

Test plan

2018-01-25 5 15 44

@codecov-io
Copy link

codecov-io commented Jan 24, 2018

Codecov Report

Merging #5389 into master will increase coverage by 0.9%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #5389     +/-   ##
=========================================
+ Coverage   61.32%   62.23%   +0.9%     
=========================================
  Files         205      205             
  Lines        6925     6925             
  Branches        3        3             
=========================================
+ Hits         4247     4310     +63     
+ Misses       2677     2614     -63     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-cli/src/reporters/utils.js 90% <0%> (+29%) ⬆️
...ackages/jest-cli/src/reporters/summary_reporter.js 70.49% <0%> (+55.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4585c73...480269f. Read the comment docs.

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Hey, thanks for improving Jest test coverage! Left some comments inlined

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
Collaborator

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

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

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

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
Collaborator

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

process.stderr.write = write;
});

describe('onRunComplete', () => {
Copy link
Collaborator

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

@kdnakt kdnakt changed the title Add summary_reporter.test.js WIP: Add summary_reporter.test.js Jan 26, 2018
@kdnakt
Copy link
Contributor Author

kdnakt commented Jan 26, 2018

Thanks for the comments. I'll fix them in a few days.

@kdnakt kdnakt changed the title WIP: Add summary_reporter.test.js Add summary_reporter.test.js Jan 26, 2018
@kdnakt
Copy link
Contributor Author

kdnakt commented Jan 26, 2018

@thymikee Thanks for the review comments. I've just updated the code so would you have a look?

process.stderr.write = result => results.push(result);
const testReporter = new SummaryReporter(globalConfig);
testReporter.onRunComplete(new Set(), aggregatedResults);
expect(results[0] + results[1]).toMatchSnapshot();
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about results.join('')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems nice idea.


test('snapshots needs update with npm test', () => {
process.env.npm_config_user_agent = 'npm';
process.stderr.write = result => results.push(result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is already done in beforeEach

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Looks better now!

*
* 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.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants