-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Can not get proxyquire to work with a require that happens in an init function #215
Comments
Hey, would you mind creating a simple repro project with this case? I think I understand what you're trying to do here but it'd be a big help to be able to see the error and debug it directly. |
The failing code is in a private repo but I will create a public repo that demos the bug. I will respond to this thread as soon as it is ready but I may not be able to get to it until Monday. Thanks!! |
Cool, thank you! I'll leave this open while you work on that. |
An ideal repro project is setup such that we can |
OK. Maybe there isn't an error in your code. It looks like my code must be at fault. Here is the repo I created so you can see what I was doing. But I really think it is my issue now and not yours. |
😄 Thanks, that often happens with a repro, hopefully it's a helpful exercise! |
I figured out what happened that made me think this was a bug. In my tests I was using I had assumed that since I was telling proxyquire to NOT use the original required code that it would not bother trying to load the original file. In my test code I was telling the system to require a non-existent file. And Proxyquire complained that the file didn't exist. To me this felt off since I didn't need it to exist in my tests. I was overriding it through a stub after all. So it may not be a real bug, but it felt like one since I said So maybe allow proxyquire to not bother checking to see if a file really exists when using Without change I now have to force the existence of a file, in my test environment, that is never used. If So maybe it is WAD (Working as Designed), but it seems like a nice option to ignore the existence of any file that is stubbed out when using If you guys want to mark this as WAD, that's fine, but maybe add some docs letting people know that every OR: Maybe add an option into |
This is the output I get:
Proxyquire only tries to load the original to provide call-thru functionality. Setting Please do modify your example if I'm misunderstanding since as long as the tests are passing I expect it's working. |
Sorry, I forgot to change my repo. It is now changed and shows the failure. Again, this is a test only environment for me. I have a situation where I want to only stub out a file that does not exist. The code shows that. It used to require '../lazyload/one', which exists. Not it attempts to require '../lazyload/two' which does not exist but it 100% stubbed out in my test file (app.mocha.js). |
Hmm, interesting. Looking into it. |
From some quick debugging I see that these errors are rethrown unless Lines 157 to 159 in 68df3d1
For now you can probably go ahead and turn that option on. It seems to me like that functionality should be tied to |
Closes #215 * Existing test covered `@noCallThru` * Module-wide `noCallThru()` should affect `_require`
I'll check it within the hour. |
Yes. My bug is now gone. Thanks for the quick fix!! |
Closes #215 * Existing test covered `@noCallThru` * Module-wide `noCallThru()` should affect `_require`
no-issue This adds two new endpoints, one at /ghost/.well-known/jwks.json for exposing a public key, and one on the canary api /identities, which allows the Owner user to fetch a JWT. This token can then be used by external services to verify the domain * Added ghost_{public,private}_key settings This key can be used for generating tokens for communicating with external services on behalf of Ghost * Added .well-known directory to /ghost/.well-known We add a jwks.json file to the .well-known directory which exposes a public JWK which can be used to verify the signatures of JWT's created by Ghost This is added to the /ghost/ path so that it can live on the admin domain, rather than the frontend. This is because most of its uses/functions will be in relation to the admin domain. * Improved settings model tests This removes hardcoded positions in favour of testing that a particular event wasn't emitted which is less brittle and more precise about what's being tested * Fixed parent app unit tests for well-known This updates the parent app unit tests to check that the well-known route is mounted. We all change proxyquire to use `noCallThru` which ensures that the ubderlying modules are not required. This stops the initialisation logic in ./well-known erroring in tests thlorenz/proxyquire#215 * Moved jwt signature to a separate 'token' propery This structure corresponds to other resources and allows to exptend with additional properties in future if needed
no-issue This adds two new endpoints, one at /ghost/.well-known/jwks.json for exposing a public key, and one on the canary api /identities, which allows the Owner user to fetch a JWT. This token can then be used by external services to verify the domain * Added ghost_{public,private}_key settings This key can be used for generating tokens for communicating with external services on behalf of Ghost * Added .well-known directory to /ghost/.well-known We add a jwks.json file to the .well-known directory which exposes a public JWK which can be used to verify the signatures of JWT's created by Ghost This is added to the /ghost/ path so that it can live on the admin domain, rather than the frontend. This is because most of its uses/functions will be in relation to the admin domain. * Improved settings model tests This removes hardcoded positions in favour of testing that a particular event wasn't emitted which is less brittle and more precise about what's being tested * Fixed parent app unit tests for well-known This updates the parent app unit tests to check that the well-known route is mounted. We all change proxyquire to use `noCallThru` which ensures that the ubderlying modules are not required. This stops the initialisation logic in ./well-known erroring in tests thlorenz/proxyquire#215 * Moved jwt signature to a separate 'token' propery This structure corresponds to other resources and allows to exptend with additional properties in future if needed
I have some code like this:
/lib/mine.js
/app.js
The code is much more complicated then this, but this is close enough to show the problem.
I am writing tests for
app.js
above and want to useproxyquire
for the file../otherPath/otherFile
My test file is like this:
app.mocha.js
The rest of this file does not matter since the error happens when I try to use
proxyquire
onapp
I get something like the following error:
Error: Cannot find module '../otherPath/otherFile
The thing is that it should not have tried to load that module yet since I have not called
init
Is there a way to force
proxyquire
to not care if the real module was loaded usingrequire
whenproxyquire
is initially called and just allow the module to be overridden if and when it is loaded?The text was updated successfully, but these errors were encountered: