如何使用lint-staged with jest --collectCoverageFrom

时间:2022-04-08 19:44:01

I'm using lint-staged with Jest testing framework to test only changed files from last commit as described in this blog.

我正在使用lint-staged和Jest测试框架来测试上次提交中已更改的文件,如本博客所述。

My configuration is as below:

我的配置如下:

"src/**/*.{ts}": [
  "prettier --write",
  "tslint --fix --project .",
  "jest --bail --findRelatedTests",
  "git add"
]

I also want to generate coverage-report for only changed files. To do this, I have to put list of changed files in multiple places.

我还想为仅更改的文件生成coverage报告。为此,我必须将更改的文件列表放在多个位置。

jest --bail --findRelatedTests <spaceSeparatedListOfSourceFiles> --collectCoverageFrom=<glob>

jest --bail --findRelatedTests --collectCoverageFrom =

Using lint-staged, how can I limit both test and coverage-report only for changed files?

使用lint-staged,如何仅针对已更改的文件限制测试和覆盖率报告?

1 个解决方案

#1


1  

I didn't know about lint-staged. I'll give it a try. I looked for this a while ago.

我不知道皮棉上演了。我试一试。我刚才找了这个。

Have you tried?

你有没有尝试过?

"jest --bail ---coverage --findRelatedTests",

“jest --bail --- coverage --findRelatedTests”,

Jest docs say that findRelatedTests can be used together with --coverage to include a test coverage for the source files, no duplicate --collectCoverageFrom arguments needed.

Jest文档说findRelatedTests可以与--coverage一起使用来包含源文件的测试覆盖率,不需要重复的--collectCoverageFrom参数。

Should work but I haven't tried.

应该工作,但我没有尝试过。

#1


1  

I didn't know about lint-staged. I'll give it a try. I looked for this a while ago.

我不知道皮棉上演了。我试一试。我刚才找了这个。

Have you tried?

你有没有尝试过?

"jest --bail ---coverage --findRelatedTests",

“jest --bail --- coverage --findRelatedTests”,

Jest docs say that findRelatedTests can be used together with --coverage to include a test coverage for the source files, no duplicate --collectCoverageFrom arguments needed.

Jest文档说findRelatedTests可以与--coverage一起使用来包含源文件的测试覆盖率,不需要重复的--collectCoverageFrom参数。

Should work but I haven't tried.

应该工作,但我没有尝试过。