Skip to content

Commit 0b2e3e1

Browse files
refactor
1 parent c3980dc commit 0b2e3e1

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

tests/index.html

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,9 @@
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());
72+
window.benchmarkReady = true;
73+
window.dispatchEvent(new Event("benchmark-ready"));
9274
</script>
9375
</body>
9476
</html>

tests/run.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ async function test() {
9797
driver = await new Builder().withCapabilities(capabilities).build();
9898
try {
9999
await driver.get(`http://localhost:${PORT}/tests/index.html`);
100+
101+
await driver.executeAsyncScript((callback) => {
102+
window.addEventListener("benchmark-ready", callback);
103+
104+
if (window?.benchmarkReady)
105+
callback();
106+
});
107+
100108
const result = await driver.executeAsyncScript(function (callback) {
101109
window.addEventListener(
102110
"test-complete",
@@ -107,7 +115,6 @@ async function test() {
107115
}),
108116
{ once: true }
109117
);
110-
window.runnerReady = true;
111118
window.dispatchEvent(new Event("start-test"));
112119
});
113120

0 commit comments

Comments
 (0)