1
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?

よく使うJestのCLIオプションまとめ

Posted at

はじめに

自分がよく使うJestのCLIオプションをまとめておきます。

--runTestsByPath

特定のパスを指定してテストを実行したい場合に利用します。

例:

pnpm jest --runTestsByPath relative/path/to/file.spec.ts

補足:

なお、Jestでは引数としてパスを指定して実行することもできますが、この場合、正規表現になるため、特定のパスを指定する場合は明示的にrunTestsByPathオプションを使うほうが個人的には好みです。

--collectCoverageFrom

コードカバレッジを計測する対象のファイルを明示的に指定するためのオプションです。

例:

pnpm jest --coverage --collectCoverageFrom="**/file.ts"

注意点:

このオプションは正規表現ではなく、GLOBパターンで指定する必要があります。

--silent

テスト実行中の標準出力を抑制・非表示にするために使用します。

例:

pnpm jest --silent

補足:

このオプションを使用すると、console.logなどの出力が抑制され、テスト結果のみが表示されます。CIでの実行時や、ログが多すぎて見づらい場合に便利です。

環境

  • jest: 26.6.3

参考

1
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
1
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?