コマンドラインインターフェイス

npm からインストールした後、QUnit CLI (コマンドラインインターフェイス) を使用する方法

QUnit CLI オプション

Usage: qunit [options] [files]

  Files should be a space-separated list of files, directories, or glob expressions.
  Defaults to 'test/**/*.js'.

Options:
  -V, --version          output the version number
  -f, --filter <filter>  run only matching module or test names
  -m, --module <name>    run only the specified module
  -r, --reporter [name]  specify the reporter to use
  --require <module>     specify a module or script to include before running any tests
  --seed [value]         specify a seed to re-order your tests
  -w, --watch            watch files for changes and re-run the test suite
  -h, --help             display help for command

--filter

指定したフィルタに一致するテストのみを実行します。フィルタはモジュール名とテスト名に照合され、サブストリング照合 (大文字小文字を区別しない) または正規表現のどちらかになります。

例: --filter foo--filter !foo--filter "/foo/"--filter "!/foo/"

QUnit.config.filter をチェックして詳細を確認してください。

--module

指定したモジュールに属するテストのみを実行します。名前は大文字小文字を区別せずに照合されますが、それ以外は完全一致する必要があります。

例: --module foo--module "Foo"

QUnit.config.module をチェックして詳細を確認してください。

--reporter

デフォルトでは、TAP レポーターが使用されます。

別のレポーターを使用するには、qunit --reporter <name> を実行します。<name> はビルトインレポーターの名前か、js-reporters 仕様を実装した Node モジュールにすることができます。レポーターは自動的にロードされ初期化されます。

ビルトインレポーター

--require

テストの実行前にこれらのモジュールまたはスクリプトが必要です。

TypeScript (ts-node/register)、Babel (@babel/register)、または CoffeeScript (coffeescript/register) などの Node.js require フックをインストールするために使用できます。

環境をブートストラップするための独自のセットアップスクリプトや QUnit.config を調整するためにも使用できます。例:

qunit --require ./test/setup.js
// test/setup.js
QUnit.config.noglobals = true;
QUnit.config.notrycatch = true;

global.MyApp = require('./index');

使用可能なすべての設定オプションについては、QUnit.config を参照してください。

--seed

このオプションは、QUnit.config.seed をあなたに割り当てます。

Node.js CLI オプション

QUnit CLI は Node.js を使用しています。NODE_OPTIONS 環境変数を使用して、Node.js CLI オプションを渡すことができます。たとえば、--enable-source-maps または --inspect を使用するには、以下のように QUnit を呼び出します

NODE_OPTIONS='--enable-source-maps' qunit test/

コードカバレッジ

nyc でレポートを生成するコードカバレッジ

{
  "scripts": {
    "test": "nyc qunit"
  },
  "devDependencies": {
    "nyc": "*",
    "qunit": "*"
  }
}

シンプルな例については、QUnit リポジトリの /test/integration/nyc/ を参照してください。

Node.js とヘッドレスブラウザの両方におけるテストの単一テストカバレッジレポートを示す、より精巧な例については、Krinkle/example-node-and-browser-qunit を参照してください。