[英]How to dynamically set files to be used in karma test
I have node file that is running a karma test in a node app using the karma public api (I'll save writing out the code because it comes straight from http://karma-runner.github.io/0.13/dev/public-api.html ). 我有使用karma公共api在节点应用程序中运行karma测试的节点文件(我将省去写代码的步骤,因为它直接来自http://karma-runner.github.io/0.13/dev/public -api.html )。
All is fine so far, the test runs. 到目前为止一切都很好,可以运行测试。 Now I need to start serving different files to the karma run.
现在,我需要开始为业力运行提供不同的文件。 For example, I might have exampleSpec.js, example1.js, example2.js, and example3.js.
例如,我可能有exampleSpec.js,example1.js,example2.js和example3.js。 I need to serve exampleSpec and then example1-3 in sequence.
我需要依次提供exampleSpec和example1-3。
However, I don't see any documentation on this, and can't seem to get anywhere on. 但是,我没有看到任何相关文档,而且似乎也无所适从。
So, The answer ended up being pretty simple. 因此,答案最终变得非常简单。 The first argument to the server constructor is a config object, that can replace or augment the karma.conf.js, so it is posible to send in altered files arrays.
服务器构造函数的第一个参数是配置对象,可以替换或扩展karma.conf.js,因此可以发送更改后的文件数组。 Code below for posterity:
后代代码如下:
"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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.