dylanb / gulp-coverage

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

JS Generators #21

Closed rudijs closed 9 years ago

rudijs commented 9 years ago

Hi,

Currently code coverage for es6 generators won't work due to esprimajs not supporting them right?

Example err:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Line 9: Unexpected token *
    at throwError (/projects/node_modules/gulp-coverage/contrib/esprima.js:1470:21)
    at throwUnexpected (/projects/node_modules/gulp-coverage/contrib/esprima.js:1527:9)

I'm tinkering with KoaJS and was trying to test some routes which use generator functions.

Gulp task is:

  gulp.task('test', function () {
    return gulp.src(['app/**/*.spec.js'], { read: false })
      .pipe(cover.instrument({
        pattern: [
          'app/**/*.js',
          '!app/**/*.spec.js'
        ],
        debugDirectory: 'test/debug'
      }))
      .pipe(mocha())
      .pipe(cover.report({
        outFile: 'test/coverage.html'
      }));

Using mocha manually on the command line (no coverage) the tests run OK with the --harmony flag.

Have tinkered with this (no joy):

.pipe(mocha({harmony: true}))

Thanks.

dylanb commented 9 years ago

The entire project does not support them at the moment. Do you have a sample project you could share that reproduces this problem?

dylanb commented 9 years ago

After looking into this a bit more I would definitely need support in the parser in order to implement this and Esprima does not have anything related to generators available yet.

rudijs commented 9 years ago

@dylanb Thanks for the follow up Dylan.

Yeah I too think it's all in Esprima's end for this to be supported.

Where I was trying to implement this is over on some KoaJS middleware which is all es6 based stuff.

https://github.com/rudijs/koa-json-logger/blob/master/test/koa-json-logger.spec.js

For now on that I'll continue to use Istanbul - looking forward to revisiting this in the future.

Cheers.

dylanb commented 9 years ago

@rudijs I have found that the esprima actually does have some support for generators, so I am going to reopen this issue while I research a potential solution.

dylanb commented 9 years ago

ok @rudijs I have determined that this is not an issue with my module but instead is a problem with the entire Node.js system including Gulp.

Take a look at https://github.com/gulpjs/gulp/issues/437

Going to leave this open so I can make sure this works when solutions drop.

rudijs commented 9 years ago

@dylanb thanks again for the follow up on this!

dylanb commented 9 years ago

Closing this issue because it is in fact a shortcoming in esprima