cache-require-paths
cache-require-paths copied to clipboard
Does not play nice with mockery
In my test code I'm registering a substitute module for electron.
When I enable cache-require-paths it will never use the substituted module, and instead error:
Error: Cannot find module 'electron'
require("cache-require-paths")
var mockery = require("mockery")
mockery.enable()
mockery.registerSubstitute("electron", "./electron_stub")
require("electron") // <-- bomb
This will work if I remove cache-require-paths.
seems because the mockery changes the loading paths, it really affects the cache paths. Two questions
- can you move loading cache-require-paths line AFTER registerSubstitute?
- can you make a tiny unit test with local modules to show the problem, or is this only when using electron?
- I tried every combination I could think of by changing the order, but the problem still persists.
- You can just use the code I pasted above as the unit test :-)
You don't have to have electron installed, since mockery should substitute it for ./electron/stub. All you'll have to do is create the stub file at that path and run the test.