forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsdom.mjs
More file actions
52 lines (38 loc) · 1.39 KB
/
jsdom.mjs
File metadata and controls
52 lines (38 loc) · 1.39 KB
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
import { JSDOM } from 'jsdom';
import * as pc from '../src/index.js';
let jsdom;
export const jsdomSetup = () => {
const html = '<!DOCTYPE html><html><head></head><body></body></html>';
jsdom = new JSDOM(html, {
resources: 'usable', // Allow the engine to load assets
runScripts: 'dangerously', // Allow the engine to run scripts
url: 'http://localhost:3000' // Set the URL of the document
});
// Copy the window and document to global scope
global.window = jsdom.window;
global.document = jsdom.window.document;
// Copy the DOM APIs used by the engine to global scope
global.ArrayBuffer = jsdom.window.ArrayBuffer;
global.Audio = jsdom.window.Audio;
global.DataView = jsdom.window.DataView;
global.Image = jsdom.window.Image;
global.KeyboardEvent = jsdom.window.KeyboardEvent;
global.MouseEvent = jsdom.window.MouseEvent;
global.XMLHttpRequest = jsdom.window.XMLHttpRequest;
// Worker shim
global.Worker = class {
constructor(stringUrl) {
this.url = stringUrl;
}
postMessage(msg) {}
terminate() {}
onmessage = null;
addEventListener() {}
removeEventListener() {}
};
// Copy the PlayCanvas API to global scope (only required for 'classic' scripts)
jsdom.window.pc = pc;
};
export const jsdomTeardown = () => {
jsdom = null;
};