-
-
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
Changes from 8 commits
aeb8170
270362a
d7473dd
8457640
f8b7082
80cd696
9a26ddb
85d5b9d
c5bdfa3
210987e
85707c6
8f99c3e
c2b608a
38c10f8
480269f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
*/ | ||
'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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we join results with |
||
}); | ||
|
||
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', | ||
); | ||
}); | ||
}); |
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 ...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.