Closed radpet closed 9 years ago
Thanks for the feedback. Can you confirm what version of the plugin you're using? I need to update the npmjs.com package page README to reflect the following for the versions:
You most likely need to switch to v0.0.3 of the plugin. I just realized now that this doesn't show up as a version on npmjs.com, so sorry for the confusion! Here are the releases, which I just added - https://github.com/bennyhat/protractor-istanbul-plugin/releases Ben
Thanks @bennyhat, I had this issue too. When I get a chance I'll take your advice and report back.
Hello @bennyhat thanks for the response! The protractor-istanbul-plugin version is set to 0.0.3. Sadly no coverage reports is generated.
@radpet - do you have some sample code that I can reproduce this against? If not, no worries. Otherwise, can you try setting the logAssertions and failAssertions options to true?
@bennyhat Hmm yes that was useful. With logAssertions set to true i get:
[launcher] Running 1 instances of WebDriver
Test select component configuration:
․ Test select component configuration: 2958ms
1 passing (3s)
Plugin: protractor-istanbul-plugin (teardown)
[31m Fail: Coverage gathering [39m
Warning: failed to gather coverage for test
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
[00:30:54] Finished 'e2e' after 4.19 s
It is okey to skip their creation if it fails, anyway i don't know why it fails.
@radpet - in this case, here are some things to try/consider:
__coverage__
variable in the JavaScript console?__coverage__
variable is present, do you have any test steps that might be clearing out your JavaScript objects on the client side at the end of the test? Some examples of this would be history clears and server side navigation. I was running into this particular problem with my test suite, so it may be happening here as well.One other thing to note is the istanbul version that is being used for instrumentation. I will confirm if Istanbul has updated the way they store the coverage. Until then, make sure that you are instrumenting with Istanbul v0.3.19 or similar. Thanks, Ben
@radpet - sure, though it varies heavily upon how you have your test site setup. Unfortunately, protractor doesn't have anything built into it that would do the instrumentation when you run the protractor command (or at least it didn't last time I checked).
In that case, you may have to use a build tool like gulp or grunt to do the instrumentation, and then call the protractor command afterwards.
Example:
Assume you have a really simple website that is just has HTML and JavaScript and automatically connects to already setup services, etc. To run your tests after editing your JS or HTML, you would want to do the following steps in gulp:
I can try and get an example gulpfile.js uploaded soon. However, in the meantime, the gulpfile.js file would look something like this:
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var connect = require('gulp-connect');
var protractor = require('gulp-protractor');
gulp.task('pre-test', function () {
// copy your html files into the test-tmp folder for web server to serve
gulp.src('lib/**/*.html')
.pipe(gulp.dest('test-tmp/'));
// instrument source code from lib and output into the test-tmp folder
return gulp.src(['lib/**/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.pipe(gulp.dest('test-tmp/'));
});
// test tasks runs pre-test tasks first
gulp.task('test', ['pre-test'], function () {
// wrap a simple http server (listening on port 8080) around your instrumented js and copied html
connect.server({
root: 'test-tmp',
port: 8080
});
// run protractor and tell it to use protractor.conf.js in the cwd
return protractor({
configFile: path.join(__dirname, 'protractor.conf.js')
});
});
Then you could do some source code edits, and the execute the command gulp test
to instrument, spin up a small web server, and run protractor against it.
Thanks! Ben
@bennyhat :+1: Yea i have worked out that and I have the spec instrumented before i run the protractor. I am using the istanbul version you suggested.
Cool. Any luck with that? Also, are you instrumenting your spec files or your source files?
Unfortunately no, same error as before. I am instrumenting the spec that is my mistake
In this case, you'll need to instrument the source code. Do you have that available to you to transform? Sometimes, it can get tricky to instrument if it has already been minified or browserified. In this case, you may have to use a plugin like https://www.npmjs.com/package/browserify-istanbul to instrument in gulp, grunt or other browserify runner.
Here is an example of that:
...
var browserify = require('browserify');
var istanbul = require('browserify-istanbul');
var source = require('vinyl-source-stream');
gulp.task('coverage:build', function() {
return browserify({debug: true})
.add('./src/app/index.js')
.transform(istanbul())
.bundle()
.on('error', options.errorHandler('Browserify'))
.pipe(source('index.js'))
.pipe(gulp.dest('test-tmp/'));
});
...
@bennyhat Yea thank you, i lacked knowledge about how istanbul really works :). Thanks for all your help. I think i can handle the rest. I will let you know if you plugin starts working.
@radpet - Sorry for all of the confusion! Good luck!
@bennyhat I got it (party). I do really appreciate your help! :+1:
I have added the plugin to the protractor.conf.js as shown in the readme. However there is neither default 'coverage' folder created, nor created when i add the outputPath property manually. Anyway those are the logs from the protractor:
I am using protractor version 2.1.0. Thank you in advance!