Just an rough idea:
- Create a wrapper around karma to create a configuration object based on your criteria
- In this case it will be a configuration object per browser type I guess
- You can have a "configuration template" stored in a
karma.conf.js
file without the browsers property
- There's a programmatic way to "enrich" this template adding more properties
- Populate a queue with these configuration objects (it can be a simple array)
- Use the karma API to launch the karma server passing the right configuration every time
Tip: You can have at this point a "wrapper" configuration to stop or carry on if a running instance face some errors
This snippet of code shows how to load and fill a template configuration:
function getConfigTemplate(path){
var config = {
// Maybe you want to add/remove some files from the list
// based on some criteria
files: [...],
// Path of the template file
configFile: path
}
return config;
}
var template = getConfigTemplate('/path/to/the/file');
// Here I can append more stuff
template.browsers = ['Chrome']
Note: the merging strategy used in karma for the two configurations works as follow:
- If a property is on the template, then it goes straight to the final configuration
- If a property is not on the template then the configuration "wrapper" object is looked up for that property
- If you a property on the template and add more on the wrapper, only the former will used and the latter will be ignored.
This code instead can be used to "chain" your karma servers:
var currentServer = 0;
var configs = [ ... ];
function startKarmaServer(config, callback){
karma.server.start(config, function (exitCode){
if(exitCode){
// an error occurred
// stop karma!
} else {
currentServer++;
callback();
}
});
}
function startServers(){
// here some code to run the karma servers in series
}
I would recommend async.js for the startServers
function.
In case you're using an older version of karma (0.10
or below) you may have a look at this fix for closing the web server after the execution.
Also, note that the Continuos Integration flag (autoWatch
) should be off in order to make the chaining work.