Can I use Create React App Jest Testing with a test reporter without ejecting?
Asked Answered
E

2

8

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?

Elsy answered 7/2, 2020 at 22:8 Comment(0)
D
9

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"]
  }
}
Disulfide answered 7/2, 2020 at 22:29 Comment(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 AppElsy
npm test -- --reporters=jest-junit is the npm version.Advocaat
C
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",
    ...
  },
...
}
Cullender answered 7/2, 2023 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.