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 others vm hooks to allow mocking dependencies #465
Conversation
@gotwarlost I was think ... We can remove this hooks: All there functions using
exports.runInContext = function(code, contextifiedSandbox, options) {
var script = new Script(code, options);
return script.runInContext(contextifiedSandbox, options);
};
exports.runInNewContext = function(code, sandbox, options) {
var script = new Script(code, options);
return script.runInNewContext(sandbox, options);
};
exports.runInThisContext = function(code, options) {
var script = new Script(code, options);
return script.runInThisContext(options);
}; We only needed hook the |
Not true - those other functions use the script constructor directly - they don't use |
@@ -139,6 +149,22 @@ function unhookRequire() { | |||
function hookCreateScript(matcher, transformer, opts) { | |||
opts = opts || {}; | |||
var fn = transformFn(matcher, transformer, opts.verbose); | |||
|
|||
var orgRunInContext = originalScript.prototype.runInContext, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these assignments to top-level variables so that they are initialized early - otherwise by the time someone calls hookCreateScript
- the original values could have been re-assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
What's the state about this? I'm trying to test scripts that will be run on a embedded v8 context. So, I'm using Jest using |
Add vm.runInNewContext: the same implementation of @laurentgoudet in #294 (fixes #293)
Add vm.runInContext: its very similar a vm.runInNewContext
and
Add support to Script.runInContext to fixes #254