Jest + TypeScript + Puppeteer で Coverage が出ないとき

前提条件

  • Puppeteer は関係ないかもしれないです
  • 各種バージョンは以下のとおりです*1
  "devDependencies": {
    "@types/expect-puppeteer": "^3.3.1",
    "@types/jest": "^24.0.18",
    "@types/jest-environment-puppeteer": "^4.3.1",
    "@types/jest-image-snapshot": "^2.8.0",
    "@types/puppeteer": "^1.19.1",
    "eslint": "^6.4.0",
    "eslint-config-standard": "^14.1.0",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-node": "^10.0.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.1",
    "eslint-plugin-vue": "^5.2.3",
    "jest": "^24.9.0",
    "jest-image-snapshot": "^2.11.0",
    "jest-puppeteer": "^4.3.0",
    "puppeteer": "^1.20.0",
    "reg-suit": "^0.8.0",
    "ts-jest": "^24.1.0",
    "typescript": "^3.6.3",
    "webpack-dev-server": "^3.8.0"
  },

結論

Jest の設定内容から、testRegex: を削除する。

testRegex: とは

The pattern or patterns Jest uses to detect test files. By default it looks for .js, .jsx, .ts and .tsx files inside of __tests__ folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). test.js または spec.js といったファイルについても同様に見つけます。 See also testMatch [array], but note that you cannot specify both options.

理由

分かりません……。

補足

過去には以下のような問題もあったようですが、今回の解決には関係ありません(効果がありません)でした。

*1:package.json より

Powered by はてなブログ