Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Is it possible to get jest junit report generated without ejecting? #207

Closed
attila123 opened this issue Dec 15, 2017 · 3 comments
Closed

Comments

@attila123
Copy link

attila123 commented Dec 15, 2017

Is this a bug report?

No, a question, and a possible feature request.

I need to generate junit xml files from the jest test results to feed them to Jenkins.
There seems to be at least two solutions for that: jest-junit (https://www.npmjs.com/package/jest-junit) and jest-junit-reporter (https://www.npmjs.com/package/jest-junit-reporter). jest-junit seems to be more configurable, but I did not try them yet. I am not sure, probably the reports could be also be generated somehow via jasmine (I don't know jest, but somewhere I read that jasmine is jest's default framework, or sg like that?).
jest-junit and jest-junit-reporter seems to require setting the jest option "testResultsProcessor", however it is not possible with react-scripts-ts (affected version is 2.8.0, currently the latest).
I know this limitation comes from create-react-app, but could probably no problem if it is implemented in react-scripts-ts first.

After trying to install a reporter (by setting testResultsProcessor in package.json's "jest" section, I get):


  • 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.

So currently my best bet seems to be ejecting, and maybe revert that once this is solved.

Should I also create such a ticket on the create-react-app project (in fact, I don't use and know that)?
On their npm page https://www.npmjs.com/package/@ontruck/react-scripts jest-junit is somehow already there as a dependency, but I did not investigated that.

@DorianGrey
Copy link
Collaborator

I've found this note on a PR in the CRA repository:
facebook/create-react-app#1990 (comment)
And another note on a feature request here:
facebook/create-react-app#2474
The test script picks up CLI parameters and gives them higher precedence over the config. Does using this change in your package.json work for you? (In our case, it should be something like "test:ci": "react-scripts-ts test --testResultsProcessor=jest-junit").

Otherwise - personally, I don't have a problem with adding a junit reporter by default, since this output format is widely used / supported on most CI systems. Even though it would make rebasing slightly more difficult.

@hellothisisjon
Copy link

@attila123 I'm currently using jest-sonar-reporter to generate a test-report.xml in jenkins, like @DorianGrey said you just need to add --testResultsProcessor yourprocessorhere in your test script in package.json.
Mine is like this: "test": "react-scripts-ts test --env=jsdom --testResultsProcessor ./node_modules/jest-sonar-reporter", it works and I haven't had to eject.

@attila123
Copy link
Author

@DorianGrey @hellothisisjon thank you very much for the solution, it worked.
So I close this issue now.

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

3 participants