thlorenz/proxyquire — pull request #8 by danielmoore (2012-11-25 03:21:48+00:00)
Title: Remove the need to copy files

1. I renamed `resolve` to `load` to be more in follow the naming scheme given by the implementation of the `Module` prototype in node. `require.resolve` merely returns the id (full file path) of the module.
2. I refactored proxyquire into a prototype so that state from one test suite (like `.noCallThru`) does not bleed into another.
* To keep things simple for the 90% case, `proxyquire(...)` by default runs the default conifg.
* When a user needs it, they can call `proxyquire.create()` to access stateful features.
3. `load` (previously `resolve`) now uses `require.extensions` to do its work. The process is simple:
1. Resolve the request and take note of the value in `require.cache`. Delete the cached item if it exists.
2. Override the extensions of all stub types so that when a request comes, override the `require` function on the module and forward the call to the usual extension handler.
3. Call the usual require for the request
4. Reset everything that was overridden