question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow configuring reporters for Jest

See original GitHub issue

Would it be possible to add functionality to configure custom reporters for Jest, without doing an eject?

This kind of functionality is already implemented for coverage tools https://github.com/facebookincubator/create-react-app/issues/1785

My use case: I am running builds in Jenkins, and I would like to create JUnit XML formatted test reports so that the test results are nicely integrated with Jenkins UI.

I tried using this: https://www.npmjs.com/package/jest-junit and configured package.json like this

"jest": {
  "testResultsProcessor": "./node_modules/jest-junit"
}

The end result is this:

Out of the box, Create React App only supports overriding these Jest options:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold
  • snapshotSerializers.

These options in your package.json Jest configuration are not currently supported by Create React App:

  • testResultsProcessor

If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.

There is another reporter package that is seems to do similar thing: https://github.com/michaelleeallen/jest-junit-reporter

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

26reactions
gaearoncommented, Jul 20, 2017

You should be able to pass it as a command line option. Since it doesn’t seem to make sense for non-CI runs, you might as well do it like this:

  "test": "react-scripts test",
  "test:ci": "react-scripts test --testResultsProcessor ./node_modules/jest-junit",

and then set your CI server to run npm run test:ci.

Hope this helps!

16reactions
jamimecommented, Jul 9, 2018

@konekoya "test:ci": "react-scripts test --env=jsdom --reporters=default --reporters=jest-junit",

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
Indicates whether the coverage information should be collected while executing the test. Because this retrofits all executed files with coverage ...
Read more >
Configuring package.json · Jest
These options let you control Jest's behavior in your package.json file. ... A list of reporter names that Jest uses when writing coverage...
Read more >
Supercharging Jest with Custom Reporters - Bruno Scheufler
The Jest configuration, located in jest.config.js , contains just the ... Now, let's get to the main part of our reporter: I installed...
Read more >
use coverage reporters specified in Jest config when running ...
Jest : use coverage reporters specified in Jest config when running tests with coverage.
Read more >
@jest/reporters | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found