jeffrifwald/babel-istanbul

babel-istanbul doesn't work with Babel > 6

Closed this issue · 5 comments

jails commented

I spent a couple of hours on it and looks like babel-istanbul as well as babel doesn't work with Babel > 6 transpiling.

I created a sample repo with 3 branches:

  • master (with babel > 6 dependency)
  • babel-istanbul (with babel > 6 dependency)
  • babel5 (with babel 5 dependency)
  • commonjs (with no transpiling)

With babel 5 & commonjs branches I was able to generate some coverage with babel-istanbul as well as istanbul using:

npm run coverage-report

However looks like ES6 import statements are just ignored with babel > 6 with babel-istanbul as well as istanbul.

Am i missing something obvious or it can be related to this change ?

Thank you.

PS:
don't forget to rm -rf node_modules when switching branches.

I am successfully covering code with babel 6.1.5, so it likely has something to do with your setup. Why are you not using presets instead of plugins? There are weird order dependencies created when you make plugins. Does your code work if you use babel-preset-es2015 instead of all of those plugins?

jails commented

Well no luck. Just created a new babel-preset-2015 with only babel-preset-es2015 enabled and it ended up to the same result. Looks like all import are ignored.

This example repo is set up in a really strange way. Istanbul is having trouble figuring out what you want to cover. If you want files to be covered, you have to specify which folders are going to be covered if those files do not live in the default folders.

To make your example work, I changed test/index.js to:

import 'chai-jasmine';
import { Example } from '..';

describe('Example', function() {

  it('returns hello', function() {

    var example = new Example();
    expect(example.hello()).toBe('world');

  });

});

I also installed babel-cli and changed the coverage-report command to:

babel-node node_modules/.bin/babel-istanbul cover _mocha

Doing those two things above made the coverage work for me.

jails commented

Thanks a lot for the head up !
Well the set up is directly related to mocha which uses test as default dir while jasmine uses spec as default dir, so I needed a couple of redirect to make things work for both binary.

Anyway I realized that require('babel-core/register'); was the issue. Looks like babel had in its 5.x branch the following patch to deal with istanbul's hook.

For the 6.x branch looks like there's an opened PR which seemed to be related to the issue.

Anyway the only working solution right now seems to be use babel-node instead of require('babel-core/register'); so the babel's hook will be applied first and won't override istanbul one.

Thank you for your feedback.

jails commented

By the way https://github.com/douglasduteil/isparta works too if maintaining this fork become too time consuming.