Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use lint-staged with jest --collectCoverageFrom

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

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.

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

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

like image 574
ozm Avatar asked Feb 24 '18 15:02

ozm


1 Answers

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 docs say that findRelatedTests can be used together with --coverage to include a test coverage for the source files, no duplicate --collectCoverageFrom arguments needed.

Should work but I haven't tried.

like image 191
bamse Avatar answered Oct 09 '22 02:10

bamse