问题
gulp-karma suggests an external config file like this:
module.exports = {
basePath: '',
singleRun: true
};
I want an external config file like this (grunt-karma style):
module.exports = function(config) {
config.set({
basePath: '',
singleRun: true
});
};
How to use the proper config file
with karma API.
Details:
I am using gulp-karma, and as mentioned there, i have to implement it on my own.
Karma API is very simple:
var server = require('karma').server;
server.start(config, done);
config
variable is vague. It is a plain object with configuration:
var config = {
basePath: '',
singleRun: true
// ...
}
Let's take a look at grunt-karma:
Sample grunt-karma config:
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
grunt-karma configuration can take a configFile
option, which is not documented anywhere.
I can see, i can pass a configFile
option from karma source code:
var config = cfg.parseConfig(cliOptions.configFile, cliOptions);
Is there a documentation for the Karma API that mentions configFile
option, how does grunt-karma know to
use it.
回答1:
This question is surprisingly relevant, and most of these comments breeze over the actual question posed at the end of this post: "How does grunt-karma know to use a config object with a property called configFile
.
I, too, have been wondering the same thing as that property is not listed anywhere in the karma config docs. For instance, if I would like to run my karma tests via the public API in my gulpfile. It would look like this: ...
var karmaConfig = require('spec/karma.conf.js');
// where my config file exports an object with properties like exclude:, path:
karma.start(karmaConfig)}, process.exit);
This would work fine, except if I wanted to export the config function so I can use the config constants (outlined here):
// allows me to do this
module.exports = function(config) {
config.set({
logLevel: config.LOG_INFO
});
}
But there's no way to get this to work unless you use something like this:
karma.start({configFile: 'spec/karma.conf.js'}, process.exit);
Where I simply pass in an object with a property configFile
that points to the actual config file.
Karma docs don't mention this anywhere (as of this comment), but it's the only way to accomplish running my test via the API while using the config function export method.
来源:https://stackoverflow.com/questions/24871069/karma-public-api-lacks-configfile-option