-
-
Notifications
You must be signed in to change notification settings - Fork 879
/
testpage.js
42 lines (37 loc) · 1.04 KB
/
testpage.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
export default function test(callback) {
const style = document.createElement('style');
style.appendChild(
document.createTextNode(
[
'body {font-family: monospace;}',
'dt, dd {display: inline-block; margin: 0;}',
'dt {min-width: 15em;}',
].join('\n')
)
);
document.body.appendChild(style);
function addTest(title, result) {
// join() result if it's array-like
if (result instanceof Uint8Array || Array.isArray(result)) {
result = Array.prototype.join.apply(result);
}
let el;
if (result === undefined) {
el = document.createElement('h2');
el.innerHTML = title;
} else {
el = document.createElement('div');
el.className = 'test_result';
el.innerHTML = '<dt>' + title + '</dt>: <dd>' + result + '</dd>';
}
document.body.appendChild(el);
}
function done() {
const div = document.createElement('h2');
div.id = 'done';
document.body.appendChild(div);
}
window.onload = function () {
callback(addTest, done);
};
}