-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
executable file
·72 lines (57 loc) · 1.64 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
var jsdom = require("jsdom");
function assign (destination, source) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
destination[key] = source[key];
}
}
return destination;
}
var jsdomBrowser = function (baseBrowserDecorator, config) {
baseBrowserDecorator(this);
var self = this;
this.name = "jsdom";
this._start = function (url) {
self.window = null;
if (jsdom.JSDOM) { // Indicate jsdom >= 10.0.0 and a new API
var virtualConsole = new jsdom.VirtualConsole();
virtualConsole.sendTo(console);
virtualConsole.removeAllListeners("clear");
var jsdomOptions = {
resources: "usable",
runScripts: "dangerously",
virtualConsole: virtualConsole
};
if (config && config.jsdom) {
jsdomOptions = assign(jsdomOptions, config.jsdom);
}
jsdom.JSDOM.fromURL(url, jsdomOptions).then(function (dom) {
self.window = dom.window;
});
} else {
var jsdomOptions = {
url: url,
features : {
FetchExternalResources: ["script", "iframe"],
ProcessExternalResources: ["script"]
},
created: function (error, window) {
self.window = window;
}
}
if (config && config.jsdom) {
jsdomOptions = assign(jsdomOptions, config.jsdom);
}
jsdom.env(jsdomOptions);
}
};
this.on("kill", function (done) {
self.window && self.window.close();
self.emit("done");
process.nextTick(done);
});
};
jsdomBrowser.$inject = ["baseBrowserDecorator", "config.jsdomLauncher"];
module.exports = {
"launcher:jsdom": ["type", jsdomBrowser]
};