4

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?

1
  • Your configuration doesn't seem to match what's shown on the jest-junit page, why have you diverged from that? Commented Nov 14, 2018 at 8:27

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@twinlakes What do you mean by duplicate? In the end, I didn't add anything to package.json. I simply added the --reporters arguments to the test command.
It is because jest will produce two types of reports: default and jest-junit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.