Skip to content

Commit 2e20ee6

Browse files
pyoortysmith
authored andcommitted
style: apply prettier
1 parent 67405b9 commit 2e20ee6

File tree

1 file changed

+153
-150
lines changed

1 file changed

+153
-150
lines changed

src/grizzly/common/harness.html

Lines changed: 153 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
3-
<head>
4-
<meta charset=UTF-8>
5-
<title>Grizzly &sdot; Harness</title>
6-
<style>
7-
body {
8-
background-color: #222;
9-
color: #ccc;
10-
font-family: monospace;
11-
font-size: 1.2em;
12-
}
13-
</style>
14-
<script>
15-
let close_after, limit_tmr
16-
let sub = null
17-
let time_limit = 0
18-
let worker = null
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Grizzly &sdot; Harness</title>
6+
<style>
7+
body {
8+
background-color: #222;
9+
color: #ccc;
10+
font-family: monospace;
11+
font-size: 1.2em;
12+
}
13+
</style>
14+
<script>
15+
let close_after, limit_tmr;
16+
let sub = null;
17+
let time_limit = 0;
18+
let worker = null;
1919

20-
let grzDump = (msg) => {
21-
console.log(`[grz harness][${new Date().toUTCString()}] ${msg}\n`)
22-
}
20+
let grzDump = (msg) => {
21+
console.log(`[grz harness][${new Date().toUTCString()}] ${msg}\n`);
22+
};
2323

24-
let setMsg = (msgStr) => {
25-
try {
26-
document.getElementById('msg').innerHTML = msgStr
27-
} catch(e) {
28-
grzDump(`setMsg error: ${e}`)
29-
}
30-
}
24+
let setMsg = (msgStr) => {
25+
try {
26+
document.getElementById("msg").innerHTML = msgStr;
27+
} catch (e) {
28+
grzDump(`setMsg error: ${e}`);
29+
}
30+
};
3131

32-
let startPolling = () => {
33-
if (worker) {
34-
worker.terminate()
35-
}
32+
let startPolling = () => {
33+
if (worker) {
34+
worker.terminate();
35+
}
3636

37-
const workerCode = `
37+
const workerCode = `
3838
let pollInterval = null;
3939
4040
self.onmessage = function(e) {
@@ -53,131 +53,134 @@
5353
};
5454
`;
5555

56-
const blob = new Blob([workerCode], {type: 'application/javascript'})
57-
worker = new Worker(URL.createObjectURL(blob))
56+
const blob = new Blob([workerCode], { type: "application/javascript" });
57+
worker = new Worker(URL.createObjectURL(blob));
5858

59-
worker.onmessage = function(e) {
60-
if (e.data.type === 'poll') {
61-
// Check window status
62-
try {
63-
if (!sub || sub.closed) {
64-
grzDump('Worker poll: sub is closed, calling main()')
65-
worker.postMessage({command: 'stop'})
66-
setTimeout(main)
67-
}
68-
} catch (error) {
69-
grzDump(`Worker poll error: ${error}`)
70-
worker.postMessage({command: 'stop'})
71-
setTimeout(main, 500)
72-
}
73-
}
74-
}
59+
worker.onmessage = function (e) {
60+
if (e.data.type === "poll") {
61+
// Check window status
62+
try {
63+
if (!sub || sub.closed) {
64+
grzDump("Worker poll: sub is closed, calling main()");
65+
worker.postMessage({ command: "stop" });
66+
setTimeout(main);
67+
}
68+
} catch (error) {
69+
grzDump(`Worker poll error: ${error}`);
70+
worker.postMessage({ command: "stop" });
71+
setTimeout(main, 500);
72+
}
73+
}
74+
};
7575

76-
worker.onerror = function(error) {
77-
grzDump(`Worker error: ${error}`)
78-
setTimeout(main, 500)
79-
}
76+
worker.onerror = function (error) {
77+
grzDump(`Worker error: ${error}`);
78+
setTimeout(main, 500);
79+
};
8080

81-
worker.postMessage({command: 'start'})
82-
}
81+
worker.postMessage({ command: "start" });
82+
};
8383

84-
let main = () => {
85-
// if limit_tmr is set, clear it
86-
if (limit_tmr !== undefined) {
87-
clearTimeout(limit_tmr)
88-
limit_tmr = undefined
89-
}
84+
let main = () => {
85+
// if limit_tmr is set, clear it
86+
if (limit_tmr !== undefined) {
87+
clearTimeout(limit_tmr);
88+
limit_tmr = undefined;
89+
}
9090

91-
if (sub && !sub.closed) {
92-
grzDump('Something is wrong, the harness is in a bad state!')
93-
}
91+
if (sub && !sub.closed) {
92+
grzDump("Something is wrong, the harness is in a bad state!");
93+
}
9494

95-
if ((close_after !== undefined) && (close_after-- < 1)) {
96-
grzDump('Iteration limit hit.')
97-
setMsg(
98-
'&gt; Iteration limit hit.<br>' +
99-
'&gt; Note: Open tabs can block browser from closing.<br>' +
100-
'&gt; Browser should close momentarily...'
101-
)
102-
try { window.focus() } catch(e) { }
103-
const xhr = new XMLHttpRequest()
104-
// indicate the test is complete by requesting `/grz_next_test`
105-
// this allows Sapphire to finish with the current test
106-
xhr.open('GET', '/grz_next_test', false)
107-
xhr.send(null)
108-
// close the harness to help catch browser shutdown issues
109-
if ('requestIdleCallback' in window) {
110-
window.requestIdleCallback(window.close, {timeout: 500})
111-
} else {
112-
setTimeout(window.close)
113-
}
114-
}
115-
else {
116-
// open test
117-
const location = (sub !== null) ? '/grz_next_test' : '/grz_current_test'
118-
sub = window.open()
119-
if (sub === null) {
120-
setMsg(
121-
'&gt; ERROR: window.open() failed!<br>' +
122-
'&gt; Try disabling popup blocker.<br>' +
123-
'&gt; Stopped.'
124-
)
125-
grzDump('Could not open test! Blocked by the popup blocker?')
126-
}
127-
else {
128-
// null opener will prevent test case interactions with harness
129-
sub.opener = null
130-
sub.location = location
131-
// set the test case time limit
132-
if (time_limit > 0) {
133-
grzDump(`Using test case time limit of ${time_limit}`)
134-
limit_tmr = setTimeout(() => {
135-
grzDump('Test case time limit exceeded')
136-
if (sub && !sub.closed) {
137-
grzDump('Closing test case')
138-
// WARNING: simplifying this setTimeout can break the harness!
139-
setTimeout(() => {
140-
try { sub.close() } catch (e) { }
141-
})
95+
if (close_after !== undefined && close_after-- < 1) {
96+
grzDump("Iteration limit hit.");
97+
setMsg(
98+
"&gt; Iteration limit hit.<br>" +
99+
"&gt; Note: Open tabs can block browser from closing.<br>" +
100+
"&gt; Browser should close momentarily...",
101+
);
102+
try {
103+
window.focus();
104+
} catch (e) {}
105+
const xhr = new XMLHttpRequest();
106+
// indicate the test is complete by requesting `/grz_next_test`
107+
// this allows Sapphire to finish with the current test
108+
xhr.open("GET", "/grz_next_test", false);
109+
xhr.send(null);
110+
// close the harness to help catch browser shutdown issues
111+
if ("requestIdleCallback" in window) {
112+
window.requestIdleCallback(window.close, { timeout: 500 });
113+
} else {
114+
setTimeout(window.close);
142115
}
143-
}, time_limit)
144-
}
145-
startPolling()
146-
}
147-
}
148-
}
116+
} else {
117+
// open test
118+
const location =
119+
sub !== null ? "/grz_next_test" : "/grz_current_test";
120+
sub = window.open();
121+
if (sub === null) {
122+
setMsg(
123+
"&gt; ERROR: window.open() failed!<br>" +
124+
"&gt; Try disabling popup blocker.<br>" +
125+
"&gt; Stopped.",
126+
);
127+
grzDump("Could not open test! Blocked by the popup blocker?");
128+
} else {
129+
// null opener will prevent test case interactions with harness
130+
sub.opener = null;
131+
sub.location = location;
132+
// set the test case time limit
133+
if (time_limit > 0) {
134+
grzDump(`Using test case time limit of ${time_limit}`);
135+
limit_tmr = setTimeout(() => {
136+
grzDump("Test case time limit exceeded");
137+
if (sub && !sub.closed) {
138+
grzDump("Closing test case");
139+
// WARNING: simplifying this setTimeout can break the harness!
140+
setTimeout(() => {
141+
try {
142+
sub.close();
143+
} catch (e) {}
144+
});
145+
}
146+
}, time_limit);
147+
}
148+
startPolling();
149+
}
150+
}
151+
};
149152

150-
window.addEventListener('load', () => {
151-
// parse arguments
152-
const args = window.location.search.replace('?', '')
153-
if (args) {
154-
for (let kv of args.split('&')) {
155-
let [k, v] = kv.split('=')
156-
if (k === 'time_limit') {
157-
time_limit = Number(v)
158-
} else if (k === 'close_after') {
159-
close_after = Number(v)
160-
} else {
161-
grzDump(`unknown arg '${k}'`)
162-
}
163-
}
164-
}
165-
// update msg
166-
setMsg('&gt; Running...')
167-
// begin iterations
168-
setTimeout(main)
169-
})
153+
window.addEventListener("load", () => {
154+
// parse arguments
155+
const args = window.location.search.replace("?", "");
156+
if (args) {
157+
for (let kv of args.split("&")) {
158+
let [k, v] = kv.split("=");
159+
if (k === "time_limit") {
160+
time_limit = Number(v);
161+
} else if (k === "close_after") {
162+
close_after = Number(v);
163+
} else {
164+
grzDump(`unknown arg '${k}'`);
165+
}
166+
}
167+
}
168+
// update msg
169+
setMsg("&gt; Running...");
170+
// begin iterations
171+
setTimeout(main);
172+
});
170173

171-
// Clean up worker when page unloads
172-
window.addEventListener('beforeunload', () => {
173-
if (worker) {
174-
worker.terminate()
175-
}
176-
})
177-
</script>
178-
</head>
179-
<body>
180-
<h4>Grizzly &sdot; Harness</h4>
181-
<div id='msg'>&gt; Loading harness...</h4>
182-
</body>
174+
// Clean up worker when page unloads
175+
window.addEventListener("beforeunload", () => {
176+
if (worker) {
177+
worker.terminate();
178+
}
179+
});
180+
</script>
181+
</head>
182+
<body>
183+
<h4>Grizzly &sdot; Harness</h4>
184+
<div id="msg">&gt; Loading harness...</div>
185+
</body>
183186
</html>

0 commit comments

Comments
 (0)