create-react-app 以下是文本内容的翻译结果: Reporter选项为Jest

kokeuurv  于 2个月前  发布在  React
关注(0)|答案(2)|浏览(37)

你的提案是否与问题相关?

CRA 只支持覆盖少数 Jest 选项,而 reporters 不是其中之一。我知道我可以通过命令行添加报告器 --reporters=my-reporter ,但问题是我希望向其传递一些选项,但命令行界面上没有可用的报告器选项(https://jestjs.io/docs/en/next/cli#--reporters)。我真的不想放弃我的 CRA 设置,所以我希望在 Jest 配置方面能够更加灵活。

描述你希望实现的功能

这是我希望能够实现的功能:

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

描述你考虑过的替代方案

我可以使用类似 craco 的东西,但如果它能在 CRA 中(以及其他 Jest 配置)预先提供就更好了。

其他上下文

#2474
#6224

gab6jxml

gab6jxml1#

在这里也是一样。CRA真的应该支持reporter

另外,当我尝试使用jest-junit时,在#2474中提出的解决方法对我来说在监视模式下不起作用。当我尝试这样做:

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

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

一起运行npm test时,生成了所有的覆盖报告文件,除了Junit一个。我做错了什么?

cetgtptt

cetgtptt2#

抱歉,我的错误。这是jest-junit设置的问题。现在解决方法已经生效了。
然而,如果CRA支持reporterscoverage-directory,那就更加方便了。

相关问题