speedskater / babel-plugin-rewire

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

Incompatible with Sinon - Plugin Kills Sinon in Tests #174

Open krisread opened 7 years ago

krisread commented 7 years ago

Hi!

We noticed that as soon as we installed babel-plugin-rewire our sinon methods like stub() / restore() in our mocha tests are no longer working. I would guess that this plugin is somehow clobbering the functions that handle stubbing and restoring.

krisread commented 7 years ago

I have made a helpful test case with a PR for you from my fork:

https://github.com/speedskater/babel-plugin-rewire/pull/175

Please take a look, this shows that using babel-plugin-rewire breaks Sinon stub

apomortsev commented 7 years ago

I'm having the same issue with sinon.stub() having stopped working for named exports after installing babel-plugin-reqire. I was able to work around it by replacing stub() with a combination of __Rewire__() and sinon.spy() for now, but it would be great if the issue could be fixed. Thanks!

speedskater commented 7 years ago

@krisread, @apomortsev Thanks for reporting this issue and sorry for the late reply. The issue will be tackled, but this won't happen before mid of march, due to a very tight schedule. Sorry for the inconvenience.

goodgec commented 7 years ago

@speedskater Just curious if there plans for this? Thanks!

speedskater commented 7 years ago

@goodgec sorry for the delay on this issue, but I cannot predict when we will be able to fix this issue, I can only assure, that it won't be forgotten.

d1820 commented 7 years ago

Any update on this?

JingyuZ commented 6 years ago

This plugin looks very promising and we really want to use it. But we got the same issue. The workaround @apomortsev mentioned definitely works, but we have way too many tests to update all sinon.stub usages.

d1820 commented 6 years ago

you could look at overriding the stub with prototype that injected the workaround above.. just an idea