thlorenz / proxyquire

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proxyquire 2: required module is not cached

senseysensor opened this issue · comments

I cannot get work proxyquire 2.0.1 after migrating from version 1.8.0.

Probably I don't understand something, but it seems like proxyquiering module doesn't preserve cache no matter if I call noPreserveCache() or preserveCache().

After calling proxyquire version 1.8 I check require.cache and can see module I patched is in cache. So that if later patched module is required from any other place in project code, everything inside is already patched. So everybody are happy.

But using version 2.0.1 after successful requiring module (and just during that requirement everything inside is patched normally) – it doesn't appear in require.cache. So if later that module is required from any other place in project, necessary modules required in patched module are again not mocked.

There are some mentions about fixes since version 2.0, but I have plenty tests broken in version 2.0.

If you need more details I will try reproduce the issue on some small example a bit later. But unfortunately I am not sure it would be simple and issue would reproduce under simpler conditions.

Node version is 6.14.0.

commented

I have a similar issue:
When mocking a module and requiring it somewhere else later it would be overwritten with the unpatched module again.
Downgrading to 1.8.0 fixed it.

Node 9.5 here.

Same here. It worked with 1.8.0.
Node v8.9.3

this is still an issue. has any one got any fix for this?

Hi, a failing test would be appreciated here. Whether to proxyquire itself (preferable) or as a standalone project I can npm install && npm test.

The behavior of preserveCache is fairly ambiguous:

https://github.com/thlorenz/proxyquire#forcing-proxyquire-to-reload-modules

While that makes it fairly clear that the returned module is cached but what about stubs? 

I've merged a lot of caching improvements recently and I'm happy to help continue adding coverage and tightening things up.

Hi—as no one's responded with code, I'm closing this issue. Happy to continue looking into this and/or clarifying docs with specifics.