コンテンツへスキップ
LatchkeyLatchkey home

Vitest vs Jestのカバレッジ: CIでより速くレポートするのは

どちらもカバレッジを生成しますが、providerが重要です。v8のカバレッジは高速、istanbulはより精密で、VitestとJestはこれらを異なる形で公開します。

Vitestは設定可能なprovider(デフォルトはv8、またはistanbul)経由でカバレッジを収集します。Jestはデフォルトでistanbulベースのカバレッジを使います。速度と精度の差は、runnerそのものよりも、v8(高速、ネイティブ)vs istanbul(計装、精密)に帰着することが多いです。

VitestのカバレッジJestのカバレッジ
デフォルトproviderv8(高速)istanbul(babelで計装)
代替provideristanbulが利用可能config/tooling経由でv8
速度高速(v8)/より遅い(istanbul)より遅い(計装)
精度良好(v8)、高い(istanbul)高い(istanbul)
ESM/TSの扱いネイティブ設定が必要

CIでは

v8 providerを使ったVitestは、コードを計装する代わりにネイティブなV8のカウントを使うため、通常最速でカバレッジを生成し、カバレッジの実行を短縮します。istanbul(Jestのデフォルトで、Vitestのオプションでもある)はより高いコストでソースを計装し、非常に精密な行/ブランチのデータを得ます。カバレッジ時間がボトルネックなら、v8がレバーです。最も精密なブランチカバレッジが必要なら、istanbulはその時間の価値があります。

CIでのカバレッジ

リグレッションでbuildを失敗させるためにカバレッジのthresholdを課し、レポートをカバレッジサービスにアップロードします。カバレッジの実行はテストに加えてCPU作業を追加します。高速なmanaged runnerはいずれにせよカバレッジの重いスイートを短縮します。

The switching cost is mostly in the parts nobody lists

  • Assertions and mocks usually port mechanically when the target implements a compatible API; custom transformers and framework plugins do not.
  • Snapshot formats differ between runners, so plan to regenerate and review rather than port.
  • Run both suites in parallel in CI for a period and diff the results. A migration that changes which tests fail is not a migration, it is a regression you have not found yet.
  • Coverage numbers move on a runner change even when the tests do not, because instrumentation differs. Re-baseline any coverage gate deliberately.

結論

最速のカバレッジが欲しくVitestを使っているなら: v8 providerを使う。最も精密なブランチカバレッジが必要なら: istanbul(Jestのデフォルト、Vitestでも利用可能)。runnerよりもproviderが速度 vs 精度を左右します。

よくある質問

Vitest vs Jest Coverage: Which Reports Faster in CI?
Vitest collects coverage via a configurable provider (v8 by default, or istanbul). Jest uses istanbul-based coverage by default. The speed and accuracy difference often comes down to v8 (fast, native) vs istanbul (instrumented, precise) more than the runner itself.
In CI?
Vitest with the v8 provider usually generates coverage fastest because it uses native V8 counts instead of instrumenting code, which shortens the coverage run. istanbul (Jest's default, and an option in Vitest) instruments source for very precise line/branch data at higher cost.
Coverage in CI?
Enforce a coverage threshold to fail the build on regressions, and upload reports to your coverage service. Coverage runs add CPU work on top of tests; faster managed runners shorten coverage-heavy suites either way.
Which should I choose?
Want the fastest coverage and you are on Vitest: use the v8 provider. Need the most precise branch coverage: istanbul (Jest's default, also available in Vitest). The provider, more than the runner, drives speed vs precision.

関連ガイド