Reputation: 1459
In a create-react-app/[email protected] project, I'm trying to generate a coverage report using jest-junit. Unfortunately, it fails with the following:
$ yarn run test --coverage
Failed to write coverage reports:
ERROR: Error: Invalid report format [jest-junit]
STACK: Error: Invalid report format [jest-junit]
at Object.module.exports.create (D:\Users\username\Documents\Project\node_modules\istanbul-api\lib\input-error.js:6:15)
at Reporter.add (D:\Users\username\Documents\Project\node_modules\istanbul-api\lib\reporter.js:51:30)
at D:\Users\username\Documents\Project\node_modules\istanbul-api\lib\reporter.js:62:18
at Array.forEach (<anonymous>)
at Reporter.addAll (D:\Users\username\Documents\Project\node_modules\istanbul-api\lib\reporter.js:61:14)
at D:\Users\username\Documents\Project\node_modules\jest-cli\build\reporters\coverage_reporter.js:180:18
at Generator.next (<anonymous>)
at step (D:\Users\username\Documents\Project\node_modules\jest-cli\build\reporters\coverage_reporter.js:75:30)
at D:\Users\username\Documents\Project\node_modules\jest-cli\build\reporters\coverage_reporter.js:86:15
at process._tickCallback (internal/process/next_tick.js:68:7)
I encounter no errors if I run yarn run test
. The following configuration block was added to the project's package.json
file:
{
...
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.d.ts",
"!src/**/__stories__/",
"!<rootDir>/node_modules/"
],
"coverageReporters": [
"jest-junit"
]
}
...
}
Has anyone successfully configured jest-junit in a create-react-app@2 project?
Upvotes: 3
Views: 6230
Reputation: 1459
Thanks to @jonrsharpe for the quick comment. I wasn't paying close enough attention... my mistake was dropping jest-junit into coverageReporters (as opposed to reporters).
Unfortunately, create-react-app@2 does not appear to support a custom reporters configuration in package.json. Interestingly, the following command works:
$ yarn run test --coverage --reporters=default --reporters=jest-junit
I'm used to most of create-react-app's configs overriding any explicitly defined options. However, it appears an exception (or loophole?) exists for yarn run test
. With the above, I get the desired junit.xml file.
Upvotes: 9