-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test to catch issue with preserveCache not preserving correctly #134
base: master
Are you sure you want to change the base?
Add test to catch issue with preserveCache not preserving correctly #134
Conversation
I went and applied your test against 1.7.0 (and a few earlier minor versions). This behavior isn't a regression—it's never worked. I'll continue poking around in |
BTW I don't know that it makes sense to keep the module you are proxyquiring in the cache at all. Therefore your behavior never worked as you expect. Bottomline is that if you proxyquire something more than once and want to register different stubs for it each time, it HAS to delete it from the cache. |
@thlorenz I don't think this is about what's right or wrong, we could debate that all day long. The documentation states that The documentation doesn't accurately describe the true behaviour of proxyquire. One side has to change, either the docs need to be updated to describe the true behaviour or the code should be updated to implement the documented behaviour. |
Yes, @KarlPurk you are right with the proxyquire.preserveCache();
var foo1 = proxyquire('./foo', stubs);
var foo2 = proxyquire('./foo', stubs);
var foo3 = require('./foo');
// foo1, foo2 and foo3 are the same instance
assert.equal(foo1, foo2);
assert.equal(foo1, foo3); If it is not behaving like this currently I agree that things are broken. What I'm not entirely sure about is though is why these tests are passing and how they are different than the tests you provided. |
@thlorenz I think @bendrucker has already done this and determined that this isn't a regression because the functionality has never been implemented as described. Looking at the test, I believe the pass here is a false possitive and the test is actually incorrect. Changing the test to the following reveals the true result: it('defaults to preserving the cache', function() {
var proxyquire = require('..');
var original = proxyquire('./samples/foo', {});
original.state = 'cached';
var proxyFoo = proxyquire('./samples/foo', { 'path': { } });
var foo = proxyquire('./samples/foo', {});
assert.equal(foo.state, 'cached');
assert.equal(foo, original);
}); |
I've fixed the test in my fork: KarlPurk@886615c Would you like me to create a PR to fix the broken test and close this PR? |
No the test was fine .. we don't want to change tests that exist. |
Okay, so to answer your question the main difference between the tests is the tests I supplied use proxyquire exclusively to test the behaviour whereas the test you linked to uses a mix of proxyquire and require. |
This PR adds an additional test to catch an issue with preserveCache not preserving the cache correctly. Currently this test fails as the bug has not been fixed.
This PR relates to #133