Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
};
@djom202
Copy link

djom202 commented Jun 7, 2016

How does it work?. You run first protractor or gulp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment