bennyhat / protractor-istanbul-plugin

Protractor plugin that collects istanbul coverage results from a page and dumps them to coverage.json files (one per spec).
MIT License
15 stars 7 forks source link

Coverage report is not created #4

Closed radpet closed 9 years ago

radpet commented 9 years ago

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:

Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver

    Test select component configuration: 
  ․ Test select component configuration: 2920ms

  1 passing (3s)

Plugin: protractor-istanbul-plugin (teardown)
    Pass:  Coverage gathering 
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
Finished 'e2e' after 4.16 s

I am using protractor version 2.1.0. Thank you in advance!

bennyhat commented 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

faceleg commented 9 years ago

Thanks @bennyhat, I had this issue too. When I get a chance I'll take your advice and report back.

radpet commented 9 years ago

Hello @bennyhat thanks for the response! The protractor-istanbul-plugin version is set to 0.0.3. Sadly no coverage reports is generated.

bennyhat commented 9 years ago

@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?

radpet commented 9 years ago

@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)
    Fail:  Coverage gathering 
        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.

bennyhat commented 9 years ago

@radpet - in this case, here are some things to try/consider:

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

bennyhat commented 9 years ago

@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

radpet commented 9 years ago

@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.

bennyhat commented 9 years ago

Cool. Any luck with that? Also, are you instrumenting your spec files or your source files?

radpet commented 9 years ago

Unfortunately no, same error as before. I am instrumenting the spec that is my mistake

bennyhat commented 9 years ago

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.

bennyhat commented 9 years ago

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/'));
});
...
radpet commented 9 years ago

@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.

bennyhat commented 9 years ago

@radpet - Sorry for all of the confusion! Good luck!

radpet commented 9 years ago

@bennyhat I got it (party). I do really appreciate your help! :+1: