Skip to content
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

Allow configuring reporters for Jest #2474

Closed
jsyrjala opened this issue Jun 5, 2017 · 13 comments
Closed

Allow configuring reporters for Jest #2474

jsyrjala opened this issue Jun 5, 2017 · 13 comments

Comments

@jsyrjala
Copy link

jsyrjala commented Jun 5, 2017

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 #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

@gaearon
Copy link
Contributor

gaearon commented Jun 5, 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!

@gaearon gaearon closed this as completed Jun 5, 2017
@jsyrjala
Copy link
Author

jsyrjala commented Jun 6, 2017

After little bit experimentation, the correct command seems to be this. No need for -- parameter. Thanks!

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

@gaearon
Copy link
Contributor

gaearon commented Jul 20, 2017

Thanks. I edited my comment.

@CafeLungo
Copy link

This seems to work, only if I put the absolute path for the ./node_module/jest-junit. So, I had to define:

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

Now it works :-)

(I tried this with react-scripts 0.9.5 with nodejs 6.11.2)

@konekoya
Copy link

konekoya commented Jul 9, 2018

I'm trying to use the CLI option from jest-junit as mentioned by @gaearon above, but it looks like testResultsProcessor is about to deprecate and eventually, remove from Jest. Source: jest-community/jest-junit#56 (comment)

Are there any other ways that we can make the reporter works without ejecting CRA?

@jamime
Copy link

jamime commented Jul 9, 2018

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

@konekoya
Copy link

Wow! Thank you @jamime, you just made my day!

@szpigielm
Copy link

Good one @jamime. Do we think this should be included in the documentation?

@TomasHubelbauer
Copy link
Contributor

@gaearon could reporters be added here for "parity" with coverageReporters? That's the only thing I had to pass by the command line. By what key were the first 4 fields to pass along chosen? And on what grounds was merging the config object discounted? To me that looks like an easier solution all around so I am probably missing some downsides there.

@quantuminformation
Copy link

Sad times

image

image

@patricklafrance
Copy link

patricklafrance commented Oct 29, 2018

@quantuminformation I feel your pain, that's why I made all Jest options configurable when you use craco to customize your CRA installation without ejecting.

An overview of the configuration is available here.

Sample craco.config.js file:

module.exports = {
    jest: {
        configure: {
             reporters: ["<rootDir>/my-custom-reporter.js"]
        }
    }
};

@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
@facebook facebook unlocked this conversation Jan 20, 2019
@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 20, 2019

I've unlocked this as per #6224.

@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 20, 2019

If there are some proposals for how we could deal with this, I think it's worth reopening this issue - as the workaround no longer works (from what I read above).

@lock lock bot locked and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants