-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
BasicTestApp.lib.module.js
52 lines (46 loc) · 1.85 KB
/
BasicTestApp.lib.module.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
51
52
let runInitializer = false;
let resourceRequests = [];
// we are using the resource list in BootResourceCachingTest and when it's too full it stops reporting correctly
window.performance.setResourceTimingBufferSize(1000);
export async function beforeStart(options) {
const url = new URL(document.URL);
runInitializer = url.hash.indexOf('initializer') !== -1;
if (runInitializer) {
if (!options.logLevel) {
// Simple way of detecting we are in web assembly
options.loadBootResource = function (type, name, defaultUri, integrity) {
resourceRequests.push([type, name, defaultUri, integrity]);
return defaultUri;
}
}
const start = document.createElement('p');
start.innerText = 'Before starting';
start.style = 'background-color: green; color: white';
start.setAttribute('id', 'initializer-start');
document.body.appendChild(start);
}
}
export async function afterStarted() {
if (runInitializer) {
const end = document.createElement('p');
end.setAttribute('id', 'initializer-end');
end.innerText = 'After started';
end.style = 'background-color: pink';
document.body.appendChild(end);
if (resourceRequests.length > 0) {
const resourceRow = (row) => `<tr><td>${row[0]}</td><td>${row[1]}</td><td>${row[2]}</td><td>${row[3]}</td></tr>`;
const rows = resourceRequests.reduce((previewRows, currentRow) => previewRows + resourceRow(currentRow), '');
const requestTable = document.createElement('table');
requestTable.setAttribute('id', 'total-requests');
requestTable.innerHTML = `<tr>
<th>type</th>
<th>name</th>
<th>default-uri</th>
<th>integrity</th>
</tr>
${rows}
`;
document.body.appendChild(requestTable);
}
}
}