Index: test/_common.js |
=================================================================== |
--- a/test/_common.js |
+++ b/test/_common.js |
@@ -22,19 +22,22 @@ let path = require("path"); |
let SandboxedModule = require("sandboxed-module"); |
let globals = { |
atob: data => new Buffer(data, "base64").toString("binary"), |
btoa: data => new Buffer(data, "binary").toString("base64"), |
Ci: { |
}, |
Cu: { |
- import: () => |
- { |
- } |
+ import: () => {}, |
+ reportError: e => undefined |
+ }, |
+ console: { |
+ log: () => undefined, |
kzar
2016/10/05 11:36:51
I think suppressing logging for all tests might be
Wladimir Palant
2016/10/05 12:12:51
Not really. An exception in a test should still be
kzar
2016/10/05 12:18:16
Yea, a switch to enable logging would be pretty us
|
+ error: () => undefined, |
}, |
navigator: { |
}, |
onShutdown: { |
add: () => |
{ |
} |
}, |
@@ -82,23 +85,26 @@ function rewriteRequires(source) |
return source.replace(/(\brequire\(["'])([^"']+)/g, (match, prefix, request) => |
{ |
if (request in knownModules) |
return prefix + escapeString(knownModules[request]); |
return match; |
}); |
} |
-exports.createSandbox = function(extraExports) |
+exports.createSandbox = function(options) |
{ |
+ if (!options) |
+ options = {}; |
+ |
let sourceTransformers = [rewriteRequires]; |
- if (extraExports) |
- sourceTransformers.push(addExports(extraExports)); |
+ if (options.extraExports) |
+ sourceTransformers.push(addExports(options.extraExports)); |
// This module loads itself into a sandbox, keeping track of the require |
// function which can be used to load further modules into the sandbox. |
return SandboxedModule.require("./_common", { |
- globals: globals, |
+ globals: Object.assign({}, globals, options.globals), |
kzar
2016/10/05 11:36:51
(Cool, never heard of Object.assign() before.)
|
sourceTransformers: sourceTransformers |
}).require; |
}; |
exports.require = require; |