dylanb / gulp-coverage

Gulp coverage reporting for Node.js that is independent of the test runner
MIT License
60 stars 12 forks source link

gulp-coverage not getting along with rewire. #24

Closed nakardo closed 10 years ago

nakardo commented 10 years ago

My tests are failing when I use gulp-coverage and rewire __set__ method. Running mocha from terminal or just gulp-mocha seems to be working fine. This is the current configuration I have:

gulp.task('test', function () {
  gulp.src('./test/*', { read: false })
    .pipe(cover.instrument({
        pattern: ['index.js', 'src/**/*.js']
    }))
    .pipe(mocha())
    .pipe(cover.gather())
    .pipe(cover.format({
      reporter: 'html',
      outFile: 'coverage.html'
    }))
    .pipe(gulp.dest('.'))
    .pipe(exit());
});

And the error I'm getting (It applies for any var):

1) Providers should return 500 updating state on database error:
     ReferenceError: Provider is not defined
      at Object.eval (eval at __set__ (/Users/nakes/Projects/api-admin/src/handlers/provider.js:206:63), <anonymous>:1:1)
      at Object.__set__ (/Users/nakes/Projects/api-admin/src/handlers/provider.js:206:49)
      at Context.<anonymous> (/Users/nakes/Projects/api-admin/test/providers.js:87:14)
      at Test.Runnable.run (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:216:15)
      at Runner.runTest (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:373:10)
      at /Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:298:14)
      at /Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:246:23)
      at Object._onImmediate (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:275:5)

Any ideas?. Thanks!

dylanb commented 10 years ago

Can you use the debugDirectory option and post the instrumented file where the reference error is occurring?

nakardo commented 10 years ago

Sure, I've uploaded a gist for the file.

dylanb commented 10 years ago

ok, I think I know what the solution is. About to get on a plane, hopefully will have a solution for you when I land ;-)

nakardo commented 10 years ago

Thanks a lot, have a nice flight! ;)

dylanb commented 10 years ago

ok, looks like it was even easier than I thought, can you clone this repo and test? If it works for you, then I will publish the updated module.

nakardo commented 10 years ago

Sorry for the delay. It's working great now. I'll leave the issue open to close it when publishing the module if you want so. Thanks!