-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.js
62 lines (49 loc) · 1.4 KB
/
load.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
process.env.TZ = "America/Los_Angeles";
var smash = require("smash"),
jsdom = require("jsdom");
require("./XMLHttpRequest");
module.exports = function() {
var files = [].slice.call(arguments).map(function(d) { return "src/" + d; }),
expression = "d3",
sandbox = {console: console, Date: Date}; // so we can use deepEqual in tests
files.unshift("test/start");
function topic() {
var callback = this.callback;
smash.load(files, expression, sandbox, function(error, result) {
if (error) console.trace(error.stack);
callback(error, result);
});
}
topic.expression = function(_) {
expression = _;
return topic;
};
topic.sandbox = function(_) {
sandbox = _;
return topic;
};
topic.document = function(_) {
var document = jsdom.jsdom();
// Monkey-patch createRange support to JSDOM.
document.createRange = function() {
return {
selectNode: function() {},
createContextualFragment: jsdom.jsdom
};
};
sandbox = {
console: console,
XMLHttpRequest: XMLHttpRequest,
document: document,
window: document.parentWindow,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
Date: Date // so we can override Date.now in tests, and use deepEqual
};
return topic;
};
return topic;
};
process.on("uncaughtException", function(e) {
console.trace(e.stack);
});