設定

Karma では、テストを実施するためにプロジェクトに関する情報を把握する必要があります。この情報は、設定ファイルを使用して提供されます。このページでは、その設定ファイルを作成する方法を説明します。

構文と使用可能なオプションの詳細については、設定ファイルの説明書を参照してください。

設定ファイルを生成する #

karma initを使用して、設定ファイルを作成できます。

$ karma init my.conf.js

Which testing framework do you want to use?
Press tab to list possible options. Enter to move to the next question.
> jasmine

Do you want to use Require.js?
This will add Require.js plugin.
Press tab to list possible options. Enter to move to the next question.
> no

Do you want to capture a browser automatically?
Press tab to list possible options. Enter empty string to move to the next question.
> Chrome
> Firefox
>

What is the location of your source and test files?
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".
Press Enter to move to the next question.
> *.js
> test/**/*.js
>

Should any of the files included by the previous patterns be excluded?
You can use glob patterns, eg. "**/*.swp".
Press Enter to move to the next question.
>

Do you want Karma to watch all the files and run the tests on change?
Press tab to list possible options.
> yes

Config file generated at "/Users/vojta/Code/karma/my.conf.js".

設定ファイルは、CoffeeScriptでも作成できます。karma init*.coffee拡張子(例:karma init karma.conf.coffee)で実行すると、CoffeeScript ファイルが生成されます。

もちろん、設定ファイルを直接作成したり、別のプロジェクトからコピー&ペーストすることもできます ;-)

Karma を起動する #

Karma を起動するときに、設定ファイルのパスを第 1 引数として渡すことができます。

既定では、Karma は現在のディレクトリでkarma.conf.jsまたはkarma.conf.coffeeを探します。

# Start Karma using your configuration:
$ karma start my.conf.js

Karma 設定ファイルの利用可能なオプションや機能などの詳細については、設定ファイルの説明書を参照してください。

コマンドライン引数 #

設定ファイルに含まれる一部の設定は、Karma 実行時にコマンドライン引数として指定することで上書きできます。

karma start my.conf.js --log-level debug --single-run

使用可能なオプションをすべて表示するには、karma start --helpを使用して試してください。

Grunt/Gulp との統合 #