Skip to content

Commit 93c5a44

Browse files
remove global vars
1 parent c3980dc commit 93c5a44

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

tests/index.html

+1-21
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,7 @@
6868
});
6969
}
7070

71-
/**
72-
* checkIn
73-
*
74-
* This function uses two global flags to ensure that both, the runner and the html page, are ready to run the tests.
75-
*
76-
* In certain scenarios, the runner may dispatch the 'start-test' event before the HTML page has the opportunity to add its listener.
77-
* To prevent the HTML page from waiting indefinitely and never initiating its tests, the runner proactively sets a global flag to true.
78-
* This ensures that even if the 'start-test' event precedes the listener's addition, the necessary check-in process occurs, enabling the tests to proceed as expected.
79-
*
80-
**/
81-
function checkIn() {
82-
if (window.runnerReady && window.domReady) startTest();
83-
}
84-
85-
window.addEventListener("start-test", () => checkIn());
86-
document.addEventListener("readystatechange", () => {
87-
if (document.readyState === "complete") {
88-
window.domReady = true;
89-
checkIn();
90-
}
91-
});
71+
window.addEventListener("start-test", startTest);
9272
</script>
9373
</body>
9474
</html>

tests/run.mjs

+11-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,17 @@ async function test() {
107107
}),
108108
{ once: true }
109109
);
110-
window.runnerReady = true;
111-
window.dispatchEvent(new Event("start-test"));
110+
111+
if (document.readyState === "complete") {
112+
dispatchEvent(new Event("start-test"));
113+
} else {
114+
document.addEventListener("readystatechange", function onReadyStateChange() {
115+
if (document.readyState === "complete") {
116+
document.removeEventListener("readystatechange", onReadyStateChange);
117+
this.dispatchEvent(new Event("start-test"));
118+
}
119+
});
120+
}
112121
});
113122

114123
printTree(result.suite);

0 commit comments

Comments
 (0)