Jestでカバレッジを取得する
Jestでカバレッジを取得するには--coverage
オプションを指定してあげればよい。
こんな感じで出力されます。
/usr/local/bin/node /usr/local/Cellar/yarn/1.22.1/libexec/bin/yarn.js test yarn run v1.22.1 $ jest --coverage PASS __tests__/board.test.js PASS __tests__/game.test.js ----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ----------|---------|----------|---------|---------|------------------- All files | 99.04 | 97.83 | 100 | 98.92 | board.js | 98.53 | 96.88 | 100 | 98.31 | 60 const.js | 100 | 100 | 100 | 100 | game.js | 100 | 100 | 100 | 100 | vec2.js | 100 | 100 | 100 | 100 | ----------|---------|----------|---------|---------|------------------- Test Suites: 2 passed, 2 total Tests: 25 passed, 25 total Snapshots: 0 total Time: 1.605s Ran all test suites. ✨ Done in 2.70s. Process finished with exit code 0
あとはこれをGitHub Actionsと組み合わせていい感じに表示されるようにしたいなあ。