jeffrifwald / babel-istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
144 stars 23 forks source link

Does not handle es6 dependency #83

Closed Faline10 closed 6 years ago

Faline10 commented 6 years ago

Is there any way to get babel-istanbul to work on dependencies? Right now I'm receiving an "SyntaxError: Unexpected token import" error from an es6 dependency. I would think that since Babel is in the instrumenter, that it could parse this.

The code looks something like this:

// gulpfile.js
var gulp = require('gulp');
var istanbul = require('gulp-babel-istanbul'); // uses babel-istanbul
var jasmine = require('gulp-jasmine');
var sources = source:     [ 'src/**/*.js', 'test/**/*.js', 'node_modules/aDependency/src/**/*.js' ];
// Note: I get this error whether or not 'node_modules/aDependency/src/**/*.js'  is included in the sources

gulp.task('test', [ 'set-test-env' ], function() {
  gulp.src(sources)
    .pipe(istanbul({
      includeUntested: true
    }))
    .pipe(istanbul.hookRequire()) // Force `require` to return covered files
    .on('finish', function() {
      gulp.src(paths.tests)
        .pipe(jasmine({ config: require('./spec/support/jasmine.json') }))
        .pipe(istanbul.writeReports({
          dir: paths.coverage,
          reportOpts: { dir: paths.coverage },
          reporters: [ 'text', 'text-summary', 'json', 'html' ]
        }))
        .on('end', function () {
          process.exit();
        });
    });
});

//.babelrc:
{
  "presets": ["es2015"],
  "env": {
    "test": {
      "plugins": [ "rewire" ]
    }
  }
}
ajmajma commented 6 years ago

+1 having same issue with keyword import

Faline10 commented 6 years ago

I discovered the issue is that gulp cannot follow symlinks, and the dependency being piped through the src() was a symlink. Since we use symlinks in development, the solution was to detect if the source was a symlink, and if it is, use the real path. Closing this issue.