LoginSignup
3
2

More than 5 years have passed since last update.

Jestでd.tsがファイルあるときCoverage出力がエラーになる場合の対処法

Posted at

はじめに

restify + TypeScript + Jestの開発環境をセットアップしてみる な感じでTypeScript + (TS)Jestで開発しているときに "collectCoverage": true としてカバレッジレポートを出そうとして以下のようなエラーが出た

Running coverage on untested files...Failed to collect coverage from /Users/user/src/project/types/example.d.ts
ERROR: Debug Failure. Output generation failed
STACK: Error: Debug Failure. Output generation failed
    at Object.transpileModule (/Users/user/src/project/node_modules/typescript/lib/typescript.js:100526:29)

どうも *.d.ts がカバレッジ計測に含まれてしまってエラーになっているようだ。*.d.tsが入っているtypesフォルダをカバレッジ対象から除外しないといけない。

対策

Code Coverage: Uncovered lines/statements in file that only defines interfaces.

package.json
"collectCoverageFrom": [
  "src/**/*.ts",
  "!src/**/*.d.ts"
]

"!src/**/*.d.ts" がミソ。!を先頭につけたパスはカバレッジから外れるみたい。

これで通った。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2