-
Notifications
You must be signed in to change notification settings - Fork 482
/
Copy pathdom.js
27 lines (23 loc) · 773 Bytes
/
dom.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
const { JSDOM } = require('jsdom');
const Node = require('jsdom/lib/jsdom/living/node-document-position');
// We can use jsdom-global at some point if maintaining these lists is a burden.
const whitelist = ['HTMLElement', 'Performance'];
const blacklist = ['sessionStorage', 'localStorage'];
function createDOM() {
const dom = new JSDOM('', { pretendToBeVisual: true });
global.window = dom.window;
global.Node = Node;
global.document = dom.window.document;
global.navigator = {
userAgent: 'node.js',
};
Object.keys(dom.window)
.filter(key => !blacklist.includes(key))
.concat(whitelist)
.forEach(key => {
if (typeof global[key] === 'undefined') {
global[key] = dom.window[key];
}
});
}
module.exports = createDOM;