Hi,
When I run multiple karma servers to test different projects, reporter is not generating output file as expected. I have three projects, To test all projects at once, I have one gulp task which launches three karma servers with its own settings.
Here is very simple setup to reproduce the problem:
Simple spec files in project specific directories. Here is one sample:
describe('Simple Test Suite', function() {
it('Simple Spec', function() {
expect(true).toBe(true);
});
});
My karma.conf.js (without comments, self-explanatory):
module.exports = function(config) {
config.set({
basePath: __dirname,
frameworks: ['jasmine'],
files: [],
exclude: [],
preprocessors: {},
reporters: ['progress', 'bamboo'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
})
}
gulpfile.js
var gulp = require('gulp');
var Server = require('karma').Server;
var fs = require('fs');
function startServer(testport, sourcefiles, outputfilename, done) {
// Create output directory
fs.mkdir('./output', function(err) {
if (err) {
if (err.code === 'EEXIST') {}
}
});
var options = {
// karma configuration file
configFile: __dirname + '/karma.conf.js',
bambooReporter:{
filename: './output/' + outputfilename
},
port: testport,
files: [
sourcefiles
],
singleRun: true
};
var server = new Server(options, done);
server.start();
}
gulp.task('project1', function (done) {
var testPort = 9876;
var sourcefiles = __dirname + '/src/project1/**/*.spec.js';
var outputfilename = 'project1_test_results.json';
startServer(testPort, sourcefiles, outputfilename, done);
});
gulp.task('project2', function (done) {
var testPort = 9877;
var sourcefiles = __dirname + '/src/project2/**/*.spec.js';
var outputfilename = 'project2_test_results.json';
startServer(testPort, sourcefiles, outputfilename, done);
});
gulp.task('project3', function (done) {
var testPort = 9878;
var sourcefiles = __dirname + '/src/project3/**/*.spec.js';
var outputfilename = 'project3_test_results.json';
startServer(testPort, sourcefiles, outputfilename, done);
});
gulp.task('default', ['project1', 'project2', 'project3']);
When I run 'gulp project1', it creates output file './output/project1_test_results.json'. Same is true for 'gulp project2' and 'gulp project3' commands.
Running just 'gulp' starts default task which in turn starts dependent test tasks. At the end, it should create following three files in './output' directory:
project1_test_results.json
project2_test_results.json
project3_test_results.json
except it doesn't. It creates only one file which is random. I'm using latest version of karma (v0.13.9).