Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdesignory committed Dec 4, 2024
1 parent c3980dc commit 0b2e3e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
24 changes: 3 additions & 21 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,9 @@
});
}

/**
* checkIn
*
* This function uses two global flags to ensure that both, the runner and the html page, are ready to run the tests.
*
* In certain scenarios, the runner may dispatch the 'start-test' event before the HTML page has the opportunity to add its listener.
* To prevent the HTML page from waiting indefinitely and never initiating its tests, the runner proactively sets a global flag to true.
* 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.
*
**/
function checkIn() {
if (window.runnerReady && window.domReady) startTest();
}

window.addEventListener("start-test", () => checkIn());
document.addEventListener("readystatechange", () => {
if (document.readyState === "complete") {
window.domReady = true;
checkIn();
}
});
window.addEventListener("start-test", () => startTest());
window.benchmarkReady = true;
window.dispatchEvent(new Event("benchmark-ready"));
</script>
</body>
</html>
9 changes: 8 additions & 1 deletion tests/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ async function test() {
driver = await new Builder().withCapabilities(capabilities).build();
try {
await driver.get(`http://localhost:${PORT}/tests/index.html`);

await driver.executeAsyncScript((callback) => {
window.addEventListener("benchmark-ready", callback);

if (window?.benchmarkReady)
callback();
});

const result = await driver.executeAsyncScript(function (callback) {
window.addEventListener(
"test-complete",
Expand All @@ -107,7 +115,6 @@ async function test() {
}),
{ once: true }
);
window.runnerReady = true;
window.dispatchEvent(new Event("start-test"));
});

Expand Down

0 comments on commit 0b2e3e1

Please sign in to comment.