mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:15:10 +00:00
LibWeb: Prevent calling test() twice
Calling test() multiple times in the same test file is not actually valid, and can cause the following test to hang forever. So let's stop doing that in the one test that did so, and also prevent the same mistake happening again. :^) Throwing an exception on subsequent test() calls means that we don't hang, the test will fail with missing output, and we get a log message explaining why.
This commit is contained in:
parent
99fc3c7551
commit
1e6cd19b28
2 changed files with 16 additions and 7 deletions
|
@ -1,4 +1,11 @@
|
|||
var __outputElement = null;
|
||||
let __alreadyCalledTest = false;
|
||||
function __preventMultipleTestFunctions() {
|
||||
if (__alreadyCalledTest) {
|
||||
throw new Error("You must only call test() or asyncTest() once per page");
|
||||
}
|
||||
__alreadyCalledTest = true;
|
||||
}
|
||||
|
||||
if (globalThis.internals === undefined) {
|
||||
internals = {
|
||||
|
@ -17,6 +24,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
});
|
||||
|
||||
function test(f) {
|
||||
__preventMultipleTestFunctions();
|
||||
document.addEventListener("DOMContentLoaded", f);
|
||||
window.addEventListener("load", () => {
|
||||
internals.signalTextTestIsDone();
|
||||
|
@ -24,7 +32,10 @@ function test(f) {
|
|||
}
|
||||
|
||||
function asyncTest(f) {
|
||||
const done = () => internals.signalTextTestIsDone();
|
||||
const done = () => {
|
||||
__preventMultipleTestFunctions();
|
||||
internals.signalTextTestIsDone();
|
||||
};
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
f(done);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue