jhnns / rewire

Easy monkey-patching for node.js unit tests
MIT License
3.08k stars 127 forks source link

Add an option to intercept and rewire nested requires #192

Closed airhorns closed 3 years ago

airhorns commented 3 years ago

Follow up to #73

This adds support for rewire-ing the inner modules required by a rewire'd module. This is really useful if you have transitive dependencies you also want to mock, or if you are using rewire as a userland require implementation, to have rewire use it's own userland implementation for nested requires as opposed to just the outer one.

airhorns commented 3 years ago

Ended up needing a require cache too so i put together https://github.com/gadget-inc/requirefire which is a half fork of rewire that does this other stuff. I think it is different enough that it belongs somewhere else but happy to try to port the changes to rewire if you think they should be here!