7

I would like to output the results of my jest testing to a file format like JUnit without ejecting from react-scripts.

By using the --json command I can output it to JSON but I was hoping to get a format that Jenkins can process by default.

I cant seem to find if this is supported and I don't want to eject from Create React App, is there another way?

Quinma
  • 1,436
  • 2
  • 17
  • 39

2 Answers2

8

You shouldn't need to do anything fancy. Just install jest-junit and then run with the additional reporters flag:

yarn test --reporters=jest-junit

You can also add it to the jest settings of package.json. Probably something like this:

{
  "name": "your-package",
  "jest": {
    "coverageReporters": ["jest-junit"]
  }
}
zero298
  • 25,467
  • 10
  • 75
  • 100
  • 2
    Thank you, the cli option `--reporters=jest-junit` worked because this isnt a `coverageReporter` the `package.json` change wont work and the `reporters` key isnt valid in Create React App – Quinma Feb 10 '20 at 19:14
  • 6
    `npm test -- --reporters=jest-junit` is the npm version. – aude Jul 03 '20 at 03:49
0

I was able to do this with npm and the jest-teamcity reporter by modifying the package.json file.

{
...
  "scripts": {
    ...
    "test": "cross-env CI=true react-scripts test --env=jsdom --reporters=jest-teamcity",
    ...
  },
...
}
datchung
  • 3,778
  • 1
  • 28
  • 29