2016-03-30 6 views
1

ノードアプリケーションでkarmaパブリックAPIを使用してカルマテストを実行しているノードファイルがあります(コードはhttp://karma-runner.github.io/0.13/dev/public-api.htmlからそのまま出力されます)。カルマテストで使用するファイルを動的に設定する方法

これまでのところ、テストは正常です。今カルマにさまざまなファイルを提供する必要があります。たとえば、exampleSpec.js、example1.js、example2.js、example3.jsがあります。私はexampleSpecとexample1-3を順番に提供する必要があります。

しかし、私はこれに関するドキュメントは表示されておらず、どこにも登場しないようです。

+0

PLZまあ、彼らは任意の整形スペックやJavaScriptファイルである可能性があり – Zamboney

+0

exampleSpec.jsとexample1-3.jsファイルを共有します。目的は、同じ仕様に対してjavascriptファイルのセットを実行し、結果を記録することです。 – AdamCooper86

答えて

0

だから、答えはかなり簡単になった。サーバーコンストラクタへの最初の引数は、karma.conf.jsを置き換えたり拡張したりできるconfigオブジェクトです。変更されたファイル配列を送信することができます。後世のために、以下のコード:

"use strict"; 

var Server = require('karma').Server; 


var filePath = process.cwd(); 
filePath += "/karma.conf.js"; 

console.log(filePath); 

//files needs to be an array of string file matchers 
function runTests(files, port) { 
    var config = { 
     configFile: filePath, 
     files: files, 
     port: port 
    }; 
    var server = new Server(config, function(exitCode) { 
     console.log('Karma has server exited with ' + exitCode); 
     process.exit(exitCode) 
    }); 

    server.on('run_complete', function (browser, result) { 
     console.log('A browser run was completed'); 
     console.log(result); 
    }); 

    server.start(); 
} 

runTests(['test/**/*Spec.js', 'tmp/example.js'], 9876); 
runTests(['test/**/*Spec.js', 'tmp/example2.js'], 9877); 
runTests(['test/**/*Spec.js', 'tmp/example3.js'], 9878); 
関連する問題