-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Multiversion support for child require() calls in r.js #726
Comments
Ok I sort of have this working by making sure that all my modules have a reference to the localContext as in
Along with some monkey patching to the r.js file.
line 2398
I need to work out how to run the unit tests to see if my changes break anything. But this works it passes the current context along with the localRequire call. therefore the chaining of the context to its children then works. |
Added pull request to r.js |
The require passed to define()'d modules when specified like this: define(function(require){
var db = require('database');
}); will be the local require, specific to the context. Note that if require is not specified as an argument in the function passed to define(), that will be a problem, so be sure that is there. Also, for any top level calls, the example mentioned using context(['database'], function (database) {
var bootstrap = context('bootstrap');
});
With that, it should all be using local, context-specific require calls. If not, it would be good to know what part fails.
So I think this is already possible today, so closing for now, but if further discussion identifies a bug we can reopen. |
I have been trying to use multiversion suport in order to support unit testing of my require modules in node. Which works fine for the top level require() calls but not for nested require calls as they use the defaultContext instead.
For example if I create a default context that looks like this.
I then setup a bootstrap a realdatabase and a fakedatabase file
Now if i setup my test as follows.
Is there any way to make require and r.js use the newly created context throughout the chain of requires? so parent->child->child all using the some context instead of revering to the default context for child require() calls.
Thanks
The text was updated successfully, but these errors were encountered: