gulp-karma 建议使用这样的外部配置文件:
module.exports = {
basePath: '',
singleRun: true
};
我想要一个这样的外部配置文件(grunt-karma 风格):
module.exports = function(config) {
config.set({
basePath: '',
singleRun: true
});
};
如何通过 karma API 使用正确的配置文件
。
详情:
我正在使用 gulp-karma,如前所述 there , 我必须自己实现。
Karma API很简单:
var server = require('karma').server;
server.start(config, done);
config
变量含糊不清。它是一个带有 configuration 的普通对象:
var config = {
basePath: '',
singleRun: true
// ...
}
让我们来看看 grunt-karma:
grunt-karma 配置示例:
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
grunt-karma 配置可以采用configFile
选项,该选项未记录anywhere .
我可以看到,我可以从 karma source code 传递一个 configFile
选项:
var config = cfg.parseConfig(cliOptions.configFile, cliOptions);
Karma API 的文档是否提到了 configFile
选项,grunt-karma 是如何知道的?
use it .
最佳答案
这个问题出人意料地相关,而且这些评论中的大多数都轻而易举地解决了本文末尾提出的实际问题:“grunt-karma 如何知道使用具有名为 configFile
的属性的配置对象>.
我也一直在想同样的事情,因为该属性没有在 karma 配置文档中的任何地方列出。例如,如果我想通过我的 gulpfile 中的公共(public) API 运行我的 karma 测试。它看起来像这样: ...
var karmaConfig = require('spec/karma.conf.js');
// where my config file exports an object with properties like exclude:, path:
karma.start(karmaConfig)}, process.exit);
这会工作得很好,除非我想导出配置函数以便我可以使用配置常量(概述 here ):
// allows me to do this
module.exports = function(config) {
config.set({
logLevel: config.LOG_INFO
});
}
但是除非你使用这样的东西,否则没有办法让它工作:
karma.start({configFile: 'spec/karma.conf.js'}, process.exit);
我只是传入一个对象,该对象具有指向实际配置文件的属性 configFile
。
Karma 文档不要在任何地方提及这一点(截至本评论),但这是在使用配置函数导出方法时通过 API 完成运行我的测试的唯一方法。
关于javascript - Karma 公共(public) api 缺少 configFile 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871069/