如何为多个需求模块设置单元测试
How to setup unit testing for multiple require module
我正在开发一个代码库,其中代码被划分为多个需求模块。即每个部分都有自己的main.js,具有所需的配置。
我想使用Karma为整个代码库设置代码覆盖范围。
由于每个部分都有自己的requirejs配置,我为每个模块创建了一个test-main.js。
并让karma.config加载所有的test-main.js文件。
我遇到了一些问题。baseUrl之间存在冲突。
当只测试一个模块时,它运行良好。
知道吗?
您可以通过编程方式使用因果报应来链接多个因果报应运行器。Karma提供了一个API,使其以编程方式工作(这并不是很清楚IMHO——一些例子可以改进它)。
首先,您需要一个配置数组,然后您需要以编程方式调用karma并连锁调用。
创建配置阵列
function getConfiguration(filename){
return {
// you can enrich the template file here if you want
// e.g. add some preprocessor based on the configuration, etc..
//
// if not set in the config template
// make Karma server launch the runner as well
singleRun: true,
// point to the template
configFile : __dirname + filename
};
}
function createConfigurations(){
return [getConfiguration('conf1.js'), getConfiguration('conf2.js'), etc...];
}
以编程方式启动因果报应
function startKarma(conf, next){
karma.server.start(conf, function(exitCode){
// exit code === 0 is OK
if (!exitCode) {
console.log(''tTests ran successfully.'n');
// rerun with a different configuration
next();
} else {
// just exit with the error code
next(exitCode);
}
});
锁住因果报应的跑步者
// Use the async library to make things cleaner
var async = require('async');
var karma = require('karma');
var confs = createConfigurations();
async.eachSeries(confs, startKarma, function(err){
if(err){
console.log('Something went wrong in a runner');
else {
console.log('Yay! All the runners have finished ok');
}
});
相关文章:
- 显示模块模式在Knockout中设置模型的新实例
- Ajax请求返回模块设置数据
- 如何为多个需求模块设置单元测试
- Requirejs 优化器 - 模块设置无法跳过外部源
- 模块导出在作为参数传入时无法设置
- 设置 npm 模块配置的最佳方法
- 类型错误:无法在模块导出中设置 undefined 的属性
- AngularJS 我应该在哪里设置或存储模块的配置
- 如何从模块设置中调用angular factory方法
- System.NullReferenceException:对象引用未设置为对象的实例.Dotnetnuke模块创建
- 如何使用perl中的WWW::Scripter模块设置referrer
- 在模块模式中设置和获取私有变量
- 在javascript显示模块模式中计算的淘汰设置
- Backbone是如何做到的.$在CommonJS模块配置中设置
- 如何在节点.js中使用重新连接模块设置 json 值
- 在AngularJS应用程序中设置模块
- 设置Jest和Enzyme来测试React 15找不到模块React /lib/ReactTestUtils
- 设置Javascript中模块的原型
- 变量作用域(模块).导出+套接字.io设置)
- AngularJS模块设置