speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
843 stars 90 forks source link

Doesn't work with babel-plugin-istanbul #148

Closed tuckerconnelly closed 7 years ago

tuckerconnelly commented 7 years ago

When I try to use this with babel-plugin-istanbul, I get: Cannot read property 'start' of undefined

jseminck commented 7 years ago

I have set up a test project that contains this plugin together with the latest bebel-plugin-istanbul: https://github.com/jseminck/karma-rewire-istanbul-example

The interesting thing is that after the latest changes from the istanbul plugin, we can make this work when using rc4 of babel-plugin-rewire. However, upgrading to rc5 causes an issue.

You can reproduce the issue by switching the bebel-plugin-rewire version in that project to: "babel-plugin-rewire": "=1.0.0-rc-5" - and then running npm test.

24 08 2016 07:36:30.143:ERROR [coverage]: [TypeError: Cannot read property 'start' of undefined]
TypeError: Cannot read property 'start' of undefined
    at /Users/joachimseminck/Projects/karma-rewire-istanbul-example/node_modules/istanbul/lib/object-utils.js:59:44

I am not sure if this is istanbul or rewire related issue (even though the error appears in istanbul code). Why does it work with rc4 but not rc5? I've tried to debug both projects a little bit but unfortunately my understanding of either is quite limited. :(

There is also a thread on the babel-plugin-istanbul project: https://github.com/istanbuljs/babel-plugin-istanbul/issues/22

speedskater commented 7 years ago

@jseminck thanks for your effort chasing this issue across different projects. I have just tried to find out, whether this issue could be tackeled in part of babel-plugin-rewire's code as well but haven't found something till now. As soon as the linked PR regarding istanbul-lib-coverage is merged, I will try to run your sample project again.

speedskater commented 7 years ago

As the issue can be resolved by using the correct plugin order, I will close this issue.

priyajeet commented 7 years ago

@speedskater I am getting this issue with webpack 2.x. Karma 2.0.1. babel-plugin-istanbul: 3.1.2 babel-plugin-rewire: 1.0.0

{
  "presets": [
    ["es2015", { "modules": false }],
    "stage-0",
    "react"
  ],
  "plugins": [
    "transform-flow-strip-types"
  ],
  "env": {
    "test": {
      "plugins": [
        ["istanbul", {
          "exclude": [
            "**/*-test.js"
          ],
        }],
        "rewire",
        ["babel-plugin-transform-require-ignore", { "extensions": [".scss"] } ],
      ]
    }
  }
}

The ordering seems correct. Issue started arising after migrating from coverage plugin to babel-plugin-istanbul

tchock commented 7 years ago

@priyajeet @speedskater have also an issue with the "babel-plugin-istanbul" package. Two to be more precise.

The "start of undefined" error comes up when I use the HTML coverage reporter. When I don't use the HTML reporter the coverage is 100% although it should be around 98% (9 lines are now missing).

Without rewire these lines are uncovered again. Also with isparta loader it worked, but that had different problems.

speedskater commented 7 years ago

@priyajeet, @tchock thanks for brininging this issue up again. I will have a look at it, when i come to work on the plugin again. But it can take till february. @priyajeet could you please provide a minimal project which reproduces the behaviour your described in the comment above.

priyajeet commented 7 years ago

@speedskater https://github.com/priyajeet/dummy

npm install npm run test

gabrielgodoy-zz commented 7 years ago

Any update on this? I am with this issue too.