[英]How to debug Javascript test files in the browser using gulp test and karma
[英]How to dynamically set files to be used in karma test
我有使用karma公共api在节点应用程序中运行karma测试的节点文件(我将省去写代码的步骤,因为它直接来自http://karma-runner.github.io/0.13/dev/public -api.html )。
到目前为止一切都很好,可以运行测试。 现在,我需要开始为业力运行提供不同的文件。 例如,我可能有exampleSpec.js,example1.js,example2.js和example3.js。 我需要依次提供exampleSpec和example1-3。
但是,我没有看到任何相关文档,而且似乎也无所适从。
因此,答案最终变得非常简单。 服务器构造函数的第一个参数是配置对象,可以替换或扩展karma.conf.js,因此可以发送更改后的文件数组。 后代代码如下:
"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.