Open sidhuko opened 9 years ago
I understand the need to intercept require()
calls, but I am currently not planning to implement it, because then it needs to be implemented for rewire-webpack and for browserify someday too. Otherwise I will get new issues opened saying "feature xyz is not working".
You could wrap you code in an init()
function which you can call again to re-initialize the cached functions.
This is unfortunate, I'm feeling compelled to use jest exactly for this feature. I'm glad to see from #73 that you're revisiting this decision.
For intercepting require you may want to have a look at proxyquire which does exactly (and only) that. For all other overrides you can then still use rewire.
Jest would work as well afaik but is a much larger package.
@thlorenz do know you if it's possible to combine proxyquire and rewire? Meaning to load a module with injection and get private variables from it?
I have not used rewire and thus would not know, sorry.
I've been trying to use rewire with FRP languages such as ramda and experienced an issue/downfall which I'd like to bring up for discussion. This relates to previous tickets which have mentioned having a way of overriding dependencies on initial rewire call. As the isInList caches the function creation with one argument to optimise the call and improve code readability it is excluded in the
__set__
update therefore returning the wrong result until the function is moved into the executed code block (see hacked example).It is a very primitive example but when working on nested promise chains where you have nested levels it becomes cumbersome to test and fix.
Suggested fix would be to allow certain modules to be changed on initialisation;
This would stop your users needing to use other third party modules such as mockery or quire to change required modules on instantiation.
Example file:
Example test:
Hacked example file to work: