You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to rewire a module that sits quite far down the require hierarchy. Simply rewiring it at the top level is not enough. I then tried something like this:
# This in the top level on its own doesn't work
validate = rewire './validate'
validate.__set__ 'func', -> true
moduleD = rewire './moduleD'
moduleD.__set__ 'validate', validate
moduleC = rewire './moduleC'
moduleC.__set__ 'moduleD', moduleD
moduleB = rewire './moduleB'
moduleB.__set__ 'moduleC', moduleC
moduleA = rewire './moduleA'
moduleA.__set__ 'moduleB', moduleB
.. but the original validate function is still always called. A console.log at the top of validate shows it's being loaded twice - shouldn't it only be loaded once? Validate is required at least 5 different times in the app. I even rewired all of those modules with the rewired validate, but nothing has worked.
Is this a bug, not a feature, or user error?
The text was updated successfully, but these errors were encountered:
This is a feature, because this way you have the full control. Do you want the rewired version to be in the global require cache or do you just want the rewired version to be isolated – it's up to you. Imho it would not be a good style if rewire did that for you. Then there would be issues like "Add option for global require cache"...
Any chance you could add this to the docs for future users?
I would like to rewire a module that sits quite far down the
require
hierarchy. Simply rewiring it at the top level is not enough. I then tried something like this:.. but the original validate function is still always called. A
console.log
at the top of validate shows it's being loaded twice - shouldn't it only be loaded once? Validate is required at least 5 different times in the app. I even rewired all of those modules with the rewired validate, but nothing has worked.Is this a bug, not a feature, or user error?
The text was updated successfully, but these errors were encountered: