Skip to content

Instantly share code, notes, and snippets.

@darlanmendonca
Forked from jbarrus/gulpfile.js
Created April 28, 2016 14:06
Show Gist options
  • Save darlanmendonca/9866d303043c474c7c84d01746bdf4ea to your computer and use it in GitHub Desktop.
Save darlanmendonca/9866d303043c474c7c84d01746bdf4ea to your computer and use it in GitHub Desktop.
protractor coverage support with gulp and istanbul (not tested, this is just extracted from larger files to demonstrate how to get protractor coverage working)
var istanbul = require('istanbul'),
gulp = require('gulp'),
istanbul = require('gulp-istanbul');
gulp.task('js', function() {
return gulp.src('js')
.pipe(istanbul({
includeUntested: true,
coverageVariable: '__coverage__'
}))
.pipe(gulp.dest('dist/'));
});
var waitPlugin = require('./waitPlugin');
var istanbul = require('istanbul');
var collector = new istanbul.Collector();
// An example configuration file.
exports.config = {
baseUrl: 'http://localhost:3000/',
capabilities: {
'browserName': 'chrome'
},
specs: ['e2e/**/*.js'],
framework: 'jasmine2',
//see https://github.com/angular/protractor/issues/1938#issuecomment-119690252
plugins: [{path: './waitPlugin.js'}],
onPrepare: function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.addReporter(new function() {
this.specDone = function(spec) {
if (spec.status !== 'failed') {
browser.driver.executeScript('return __coverage__;').then(function(coverageResults) {
collector.add(coverageResults);
});
}
};
});
},
onComplete: function() {
istanbul.Report.create('cobertura', {dir: 'results/e2e/cobertura'})
.writeReport(collector, true);
istanbul.Report.create('lcov', {dir: 'results/e2e/lcov'})
.writeReport(collector, true);
waitPlugin.resolve();
}
};
//see https://github.com/angular/protractor/issues/1938#issuecomment-119690252
var q = require('q');
var deferred = q.defer();
exports.resolve = function() {
deferred.resolve.apply(deferred, arguments);
};
exports.teardown = function() {
return deferred.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment