Last active
August 7, 2017 10:12
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/')); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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
How does it work?. You run first protractor or gulp?