Skip to content

Commit

Permalink
add coverage in gulp to be able to test if single run or not
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiip committed Sep 16, 2015
1 parent 868505a commit 380385b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
24 changes: 6 additions & 18 deletions app/templates/_karma.conf.js
Expand Up @@ -87,25 +87,13 @@ module.exports = function(config) {
reporters: ['progress']
};

var preprocessors = {};
// This is the default preprocessors configuration for a usage with Karma cli
// The coverage preprocessor in added in gulp/unit-test.js only for single tests
// It was not possible to do it there because karma doesn't let us now if we are
// running a single test or not
var pathSrcHtml = path.join(conf.paths.src, '/**/*.html');
preprocessors[pathSrcHtml] = ['ng-html2js'];

if (config.singleRun) {
<% if (props.jsPreprocessor.key === 'noJsPrepro') { -%>
var pathSrcJs = path.join(conf.paths.src, '/**/!(*.spec).js');
preprocessors[pathSrcJs] = ['coverage'];
<% } else if (props.jsPreprocessor.key === 'coffee') { -%>
var pathTmpJs = path.join(conf.paths.tmp, '/**/!(*.spec).js');
preprocessors[pathTmpJs] = ['coverage'];
<% } else { -%>
var pathTmpJs = path.join(conf.paths.tmp, '/serve/app/index.module.js');
preprocessors[pathTmpJs] = ['coverage'];
<% } -%>
configuration.resporters.push('coverage');
}

configuration.preprocessors = preprocessors;
configuration.preprocessors = {};
configuration.preprocessors[pathSrcHtml] = ['ng-html2js'];

// This block is needed to execute Chrome on Travis
// If you ever plan to use Chrome and Travis, you can keep it
Expand Down
19 changes: 17 additions & 2 deletions app/templates/gulp/_unit-tests.js
Expand Up @@ -7,11 +7,26 @@ var conf = require('./conf');
var karma = require('karma');

function runTests (singleRun, done) {
var server = new karma.Server({
var reporters = ['progress'];
var preprocessors = {};
if (singleRun) {
var pathTmpJs = path.join(conf.paths.tmp, '/serve/app/index.module.js');
preprocessors[pathTmpJs] = ['coverage'];
reporters.push('coverage')
}
var pathSrcHtml = path.join(conf.paths.src, '/**/*.html');
preprocessors[pathSrcHtml] = ['ng-html2js'];

var localConfig = {
configFile: path.join(__dirname, '/../karma.conf.js'),
singleRun: singleRun,
autoWatch: !singleRun
}, function(failCount) {
};

localConfig.reporters = reporters;
localConfig.preprocessors = preprocessors;

var server = new karma.Server(localConfig, function(failCount) {
done(failCount ? new Error("Failed " + failCount + " tests.") : null);
})
server.start();
Expand Down

0 comments on commit 380385b

Please sign in to comment.