-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (31 loc) · 1.06 KB
/
Copy pathtest.js
File metadata and controls
36 lines (31 loc) · 1.06 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
import jsdom from 'jsdom';
import fs from 'fs';
import path from 'path';
const { JSDOM } = jsdom;
const games = ['domino', 'voidsector', 'typingspeed', 'wordscramble', 'sky-dash'];
(async () => {
for (const game of games) {
console.log(`\n--- Testing ${game} ---`);
const indexPath = path.join(process.cwd(), `dist/games/${game}/index.html`);
const html = fs.readFileSync(indexPath, 'utf-8');
const virtualConsole = new jsdom.VirtualConsole();
virtualConsole.on("error", (err) => {
console.error(`[${game} ERROR]`, err.message || err);
});
virtualConsole.on("jsdomError", (err) => {
console.error(`[${game} JSDOM ERROR]`, err.message || err);
});
try {
const dom = new JSDOM(html, {
url: `http://localhost/games/${game}/`,
runScripts: "dangerously",
resources: "usable",
virtualConsole
});
await new Promise(r => setTimeout(r, 1000));
console.log(`[${game}] DOM ready.`);
} catch (e) {
console.error(`[${game} FATAL]`, e.message || e);
}
}
})();