Skip to content

Instantly share code, notes, and snippets.

@jbarrus
Last active August 7, 2017 10:12
Show Gist options
  • Save jbarrus/286cee4294a6537e8217 to your computer and use it in GitHub Desktop.
Save jbarrus/286cee4294a6537e8217 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;
};
@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