-
Notifications
You must be signed in to change notification settings - Fork 504
/
web-runner.js
50 lines (46 loc) · 1.53 KB
/
web-runner.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
/* global document, location, addEventListener */
// Open `index.html` in a browser to run this file
import tests from "./tests-data.js";
const table = document.createElement("table");
const MAX_TESTS = 16;
let indexTest;
for (indexTest = 0; indexTest < Math.min(MAX_TESTS, tests.length); indexTest++) {
const test = tests[indexTest];
if (!test.env || test.env.includes("browser")) {
addTest(test);
}
}
document.body.appendChild(table);
if (!location.search.startsWith("?keepTests")) {
addEventListener("message", event => {
const result = JSON.parse(event.data);
if (!result.error) {
Array.from(document.querySelectorAll("tr")).find(row => row.dataset.script == result.script).remove();
}
const test = tests[indexTest];
indexTest++;
if (test) {
if (!test.env || test.env.includes("browser")) {
addTest(test);
}
} else if (!document.querySelectorAll("tr").length) {
document.body.innerHTML = "ok";
}
}, false);
}
function addTest(test) {
const row = document.createElement("tr");
const cellTest = document.createElement("td");
const cellLink = document.createElement("td");
const iframe = document.createElement("iframe");
const link = document.createElement("a");
link.textContent = test.title;
link.target = test.script;
row.dataset.script = test.script;
link.href = iframe.src = "/tests/all/loader.html#" + encodeURIComponent(JSON.stringify({ script: test.script }));
cellTest.appendChild(iframe);
cellLink.appendChild(link);
row.appendChild(cellLink);
row.appendChild(cellTest);
table.appendChild(row);
}