Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Wrong coverage output with Babel #86

Open
aaron61591 opened this issue Sep 28, 2018 · 3 comments
Open

Wrong coverage output with Babel #86

aaron61591 opened this issue Sep 28, 2018 · 3 comments

Comments

@aaron61591
Copy link

aaron61591 commented Sep 28, 2018

this is my webpack configuration in karma.conf.js:

webpack: {
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [{ loader: 'babel-loader' }],
        exclude: /(node_modules)/,
      },
      {
        test: /\.js$/,
        use: [{
          loader: 'istanbul-instrumenter-loader',
          query: { esModules: true },
        }],
        include: /(src)/,
        enforce: 'post',
      },
    ],
  },
}

html reporter result:
2018-09-28 3 16 17

instrumented file like this:

cov_20zyf0jfnw.s[0]++;
Object.defineProperty(exports, "__esModule", {
  value: true
});
cov_20zyf0jfnw.s[1]++;
exports.default = exports.network = exports.fit = void 0;
var _fit = (cov_20zyf0jfnw.s[2]++, _interopRequireDefault(require("./fit")));
var _network = (cov_20zyf0jfnw.s[3]++, _interopRequireDefault(require("./network")));

function _interopRequireDefault(obj) {
  cov_20zyf0jfnw.f[0]++;
  cov_20zyf0jfnw.s[4]++;
  return (cov_20zyf0jfnw.b[1][0]++, obj) && (cov_20zyf0jfnw.b[1][1]++, obj.__esModule) ? (cov_20zyf0jfnw.b[0][0]++, obj) : (cov_20zyf0jfnw.b[0][1]++, {
    default: obj
  });
}
var fit = (cov_20zyf0jfnw.s[6]++, _fit.default);
cov_20zyf0jfnw.s[7]++;
exports.fit = fit;
var network = (cov_20zyf0jfnw.s[8]++, _network.default);
cov_20zyf0jfnw.s[9]++;
exports.network = network;
var _default = (cov_20zyf0jfnw.s[10]++, {
  fit: fit,
  network: network
});
cov_20zyf0jfnw.s[11]++;
exports.default = _default;

if I update my webpack configuration, and run the instrumentation as a per step.

everything is ok.

@mcsmcs
Copy link

mcsmcs commented Mar 1, 2019

Can confirm switching to enforce: 'pre' corrects the output.

@foolip
Copy link

foolip commented May 15, 2019

I'm seeing a similar problem with the number of lines being affected by the combination of babel-loader and istanbul-instrumenter-loader. https://github.com/webpack-contrib/istanbul-instrumenter-loader#with-babel suggests enforce: 'post' which is surprising. I'll try both that and enforce: 'pre' as seems to have worked for @mcsmcs.

@foolip
Copy link

foolip commented May 15, 2019

I've tried both post and pre now:
GoogleChromeLabs/confluence#403
GoogleChromeLabs/confluence#404

As expected, enforce: 'pre' is what fixes the line numbering, since the instrumentation is otherwise done on the babel output. I've sent #93 in the hope that it's just a typo in the documentation, but I'm not certain that it is, something else might break?

foolip added a commit to GoogleChromeLabs/confluence that referenced this issue May 15, 2019
Currently instrumentation is running after babel, which results in
incorrect and nonsensical coverage information. The node vs. web
coverage here is an example:
https://codecov.io/gh/GoogleChromeLabs/confluence/src/f6802df5a6be89042a1db1e7b82f0a0a90906caf/lib/dao/indexed_dao.es6.js

This could be fixed by changing the order:
#404

However, it's not clear if that's correct:
webpack-contrib/istanbul-instrumenter-loader#86

There's no need to run Babel to test stable versions of Chrome or Firefox,
so just skip babel-loader.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants