facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.6k stars 26.79k forks source link

Reporter options for Jest #9019

Open jdelucaa opened 4 years ago

jdelucaa commented 4 years ago

Is your proposal related to a problem?

CRA only supports overriding a few Jest options and reporters is not one of them. I know that I can add reporters via cli --reporters=my-reporter, the problem is that I would like to pass in some options to that, but reporter options are not available via cli (https://jestjs.io/docs/en/next/cli#--reporters).

I really don't want to eject my CRA setup, so i wish it was more flexible when it comes to Jest configurations.

Describe the solution you'd like

This is what I'd like to be able to do:

"reporters": [
  "default",
  ["./node_modules/jest-cucumber/dist/src/reporter", {
    "formatter": "json",
    "path": "./reports/test-report.json"
  }]
],

Describe alternatives you've considered

I could use something like craco, but it would be even nicer to have it (and other Jest configs) out of the box in CRA.

Additional context

https://github.com/facebook/create-react-app/issues/2474 https://github.com/facebook/create-react-app/issues/6224

svdHero commented 4 years ago

Same here. CRA shoudl really support reporter.

Also when trying to use jest-junit, the proposed workaround in #2474 does not work for me in watch mode. When I try this:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --coverage --watch --reporters=default --reporters=jest-junit",
    "eject": "react-scripts eject"
  },

in combination with

  "jest": {
    "coverageReporters": [
      "json",
      "lcov",
      "text",
      "clover",
      "cobertura"
    ]
  }  

and run npm test, all cover report files are generated EXCEPT the Junit one. What am i doing wrong?

svdHero commented 4 years ago

Ah sorry. My bad. it was a problem with the jest-junit settings. The workaround works now. However, it would be way more convenienet if CRA supported reporters and also coverage-directory.