diff --git a/src/testing.zig b/src/testing.zig index 5abdd024..b3808597 100644 --- a/src/testing.zig +++ b/src/testing.zig @@ -404,6 +404,13 @@ pub fn htmlRunner(file: []const u8) !void { try page.navigate(url, .{}); _ = page.wait(2000); + const needs_second_wait = try js_context.exec("testing._onPageWait.length > 0", "check_onPageWait"); + if (needs_second_wait.value.toBool(page.main_context.isolate)) { + // sets the isSecondWait flag in testing. + _ = js_context.exec("testing._isSecondWait = true", "set_second_wait_flag") catch {}; + _ = page.wait(2000); + } + @import("root").js_runner_duration += std.time.Instant.since(try std.time.Instant.now(), start); const value = js_context.exec("testing.getStatus()", "testing.getStatus()") catch |err| { diff --git a/src/tests/html/history.html b/src/tests/html/history.html index 45ef8056..3714d5cd 100644 --- a/src/tests/html/history.html +++ b/src/tests/html/history.html @@ -2,30 +2,30 @@ - - diff --git a/src/tests/testing.js b/src/tests/testing.js index bf0ea07f..779cca8c 100644 --- a/src/tests/testing.js +++ b/src/tests/testing.js @@ -50,6 +50,15 @@ function getStatus() { // if we're already in a fail state, return fail, nothing can recover this if (testing._status === 'fail') return 'fail'; + + if (testing._isSecondWait) { + for (const pw of (testing._onPageWait)) { + testing._captured = pw[1]; + pw[0](); + testing._captured = null; + } + } + // run any eventually's that we've captured for (const ev of testing._eventually) { testing._captured = ev[1]; @@ -92,6 +101,18 @@ _registerErrorCallback(); } + // Set expectations to happen on the next time that `page.wait` is executed. + // + // History specifically uses this as it queues navigation that needs to be checked + // when the next page is loaded. + function onPageWait(fn) { + // Store callbacks to run when page.wait() happens + testing._onPageWait.push([fn, { + script_id: document.currentScript.id, + stack: new Error().stack, + }]); + } + async function async(promise, cb) { const script_id = document.currentScript ? document.currentScript.id : '