Skip to content

Commit

Permalink
Merge 01fd978 into dada1ea
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic16x committed Feb 11, 2016
2 parents dada1ea + 01fd978 commit 187796f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 20 deletions.
75 changes: 58 additions & 17 deletions gulp/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var Server = require('karma').Server;
var util = require('gulp-util');
var gulp = require('gulp');
var path = require('path');
var glob = require('glob');
var _ = require('lodash');

var error = require('../util/error');
Expand All @@ -11,10 +12,21 @@ var deps = require('../deps')(config);

var isTestDebug = util.env.d || util.env.debug;
var testRequirements = isTestDebug ? [] : ['buildTest'];
var itemInChunk = util.env['items-in-chunk'] || 10;
var karmaConf = require('../../test/karma.conf.js');

gulp.task('test', testRequirements, function (done) {
// Need for get expelled tests from karma.conf.js
var config = {};
config.set = function(obj) {
this.conf = obj;
};
karmaConf(config);
var karmaConfExcludeTests = config.conf.exclude || [];

var cliOptions = _.cloneDeep(util.env);
var modulesToTest = [];
var currentChunk = 0;

var sourcesList = deps.getJSFiles({source: 'testSource'}).concat([
'gulp/tmp/testJS/config.js',
Expand All @@ -34,27 +46,56 @@ gulp.task('test', testRequirements, function (done) {
modulesToTest = cliOptions.module.split(',');
}

var modulesToTestSourceList = [];

if (modulesToTest.length) {
modulesToTest.forEach(function (moduleName) {
sourcesList.push('src/' + moduleName + '/test/*Spec.js');
modulesToTestSourceList = modulesToTestSourceList.concat(glob.sync('src/' + moduleName + '/test/*Spec.js'));
});
} else {
sourcesList.push('src/**/test/*Spec.js');
modulesToTestSourceList = modulesToTestSourceList.concat(glob.sync('src/**/test/*Spec.js'));
}
modulesToTestSourceList = modulesToTestSourceList.concat(glob.sync('node_modules/leaflet/spec/suites/**/*Spec.js'));

modulesToTestSourceList = _.xor(modulesToTestSourceList, karmaConfExcludeTests);

var splittedModules = _.chunk(modulesToTestSourceList, itemInChunk);

var numberOfChunks = splittedModules.length;

console.log("\nITEMS IN CHUNK: " + itemInChunk + ". Use --items-in-chunk for set this.");
console.log("NUMBER OF CHUNKS: " + numberOfChunks);

var totalErr = false;

var startServer = function(err){
totalErr = err || totalErr;
console.log('\nCHUNK #' + currentChunk.toString());

var localeSourceList = sourcesList.concat(splittedModules[currentChunk]);
currentChunk++;

localeSourceList.push('node_modules/leaflet/spec/suites/SpecHelper.js');

sourcesList.push('node_modules/leaflet/spec/suites/SpecHelper.js');
sourcesList.push('node_modules/leaflet/spec/suites/**/*Spec.js');

new Server({
files: sourcesList,
configFile: path.join(__dirname, '../../test/karma.conf.js'),
browsers: test.getBrowsers(),
reporters: test.getReporters(isTestDebug),
junitReporter: test.getJunitReporter(),
action: 'run',
preprocessors: {
'gulp/tmp/testJS/src/**/*.js': ['coverage']
},
singleRun: true
}, done).start();
new Server({
files: localeSourceList,
configFile: path.join(__dirname, '../../test/karma.conf.js'),
browsers: test.getBrowsers(),
reporters: test.getReporters(isTestDebug),
junitReporter: test.getJunitReporter(),
action: 'run',
preprocessors: {
'gulp/tmp/testJS/src/**/*.js': ['coverage']
},
singleRun: true
}, currentChunk == numberOfChunks ? function(){
if (totalErr) {
process.exit(1);
}
else {
done();
}
} : startServer).start();
};
startServer();
});
6 changes: 3 additions & 3 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(config) {
client: {
captureConsole: true,
mocha: {
timeout: 120000
timeout: 480000
}
},

Expand Down Expand Up @@ -67,8 +67,8 @@ module.exports = function(config) {

// If browser does not capture in given timeout [ms], kill it
// CLI --capture-timeout 5000
captureTimeout: 120000,
browserNoActivityTimeout: 120000,
captureTimeout: 480000,
browserNoActivityTimeout: 480000,

// Auto run test on start (when browsers are captured) and exit
// CLI --single-run --no-single-run
Expand Down

0 comments on commit 187796f

Please sign in to comment.