-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Conversation
… into fix-update-command-npm
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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; |
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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', | ||
); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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
Thanks for the comments. I'll fix them in a few days. |
@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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about results.join('')
?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this 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. | ||
*/ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try it!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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. |
Summary
I just added summary_reporter.test.js
Test plan