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

Support for global? #178

Open laggingreflex opened 7 years ago

laggingreflex commented 7 years ago

It seems support for global was removed some time in the past. Any chance it might be reconsidered?

I wanted to rewire document and location which are globals but only in browser.

It also seems that sinon has a problem if you define global.document = {} https://github.com/sinonjs/sinon/issues/719.

I also want to avoid messing with globals as it opens memory leaks and other issues.

Looking at other issues I know it's been suggested to redefine globals as temporary variables const document_ = document, and that's what I'm doing now, but I'd rather want to have rewire take care of it.

speedskater commented 7 years ago

@laggingreflex. We had it working in an initial version but removed it due to its unstable nature. Maybe we can add it in a future version, but it will take some time and I am not 100% sure if this will work.