LoginSignup
0
0

Vitestのカバレッジレポートが「...」で省略されないようにする

Posted at

課題

Vitestでテストを書いている。
カバレッジをvitest run --coverageで出力しているのだが、
ファイルのパスが長すぎて以下のように3点のピリオド...で省略されてしまうことがあった。

---------------------------|---------|----------|---------|---------|-------------------
| File                      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
|---------------------------|---------|----------|---------|---------|-------------------|
| All files                 | 83.26   | 78.63    | 69.42   | 83.26   |                   |
| ...eComponents/FugaButton | 0       | 0        | 0       | 0       |                   |
| index.vue                 | 0       | 0        | 0       | 0       |                   |

以下のように省略せずに出力したい。

| src/hogeComponents/FugaButton | 0       | 0        | 0       | 0       |                   |

現状、vitest.config.tsは以下のようになっていて、
providerv8reportertextを指定している。

export default defineConfig({
  test: {
    省略
    coverage: {
      provider: "v8",
      reporter: ["text"]
    }
  }
});

解決法

ファイル名が...で潰れてしまう原因は、表の幅が狭いから。
textをreporterとして使う場合、maxColsオプションがあるため、
それを使って幅を広げてやれば良い。

以下のように設定できる。

{
  coverage: {
    provider: "v8",
    reporter: [
      ['text', { maxCols: 200 }]
    ]
  }
}

参考

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