3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vitest を GitHub Actions 上で実行するときに設定したいオプションや composite action - カバレッジレポート編

Last updated at Posted at 2024-12-06

はじめに

Vitest をプロジェクトに設定しローカル環境はもちろん CI/CD 環境でも動かす場面は少なくありません。
今回は GitHub Actions で Vitest を実行する際に設定したい内容や composite actions をまとめました。

レポーター設定

Vitest は GitHub Actinos の workflow command に対応しています。
なお、この設定は process.env.GITHUB_ACTIONStrue である場合自動的に有効になります。

もし、レポーター設定をデフォルト値以外で使用している場合は、 github-actions を追加することで利用可能です。

vite.config.ts
export default defineConfig({
   test: {
     coverage: {
       reporter: ["dot", "github-actions"],

カバレッジレポート

こちらの記事でも紹介されていましたが、 vitest-coverage-report-action を導入することで作成した Pull request にコメントでテストカバレッジを追加してくれます。

vitest-coverage-report-action を使用するためには、 reporter に下記値を定義する必要があります。

  • json-summary (必須)
  • json
vite.config.ts
export default defineConfig({
   test: {
     coverage: {
       reporter: ["json-summary", "json"],

上記内容適用した設定ファイル

上記内容適用した設定ファイルは以下のようになります。

vite.config.ts
export default defineConfig({
   test: {
     coverage: {
       reporter: ["dot", "github-actions", "json-summary", "json"],

Ref

3
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?