1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 07:08:27 -05:00

fix(test): disable preventDefault() for beforeunload event (#18911)

Fixes #18910.
This commit is contained in:
Nayeem Rahman 2023-05-03 22:10:51 +01:00 committed by Levente Kurusa
parent 675aa94d12
commit 434c80bd62
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4
8 changed files with 40 additions and 12 deletions

View file

@ -114,6 +114,11 @@ itest!(finally_timeout {
output: "bench/finally_timeout.out", output: "bench/finally_timeout.out",
}); });
itest!(before_unload_prevent_default {
args: "bench --quiet bench/before_unload_prevent_default.ts",
output: "bench/before_unload_prevent_default.out",
});
itest!(group_baseline { itest!(group_baseline {
args: "bench bench/group_baseline.ts", args: "bench bench/group_baseline.ts",
exit_code: 0, exit_code: 0,

View file

@ -361,6 +361,11 @@ itest!(test_with_custom_jsx {
output: "test/hello_world.out", output: "test/hello_world.out",
}); });
itest!(before_unload_prevent_default {
args: "test --quiet test/before_unload_prevent_default.ts",
output: "test/before_unload_prevent_default.out",
});
#[test] #[test]
fn captured_output() { fn captured_output() {
let context = TestContext::default(); let context = TestContext::default();

View file

@ -0,0 +1,7 @@
cpu: [WILDCARD]
runtime: deno [WILDCARD]
[WILDCARD]/before_unload_prevent_default.ts
benchmark time (avg) (min … max) p75 p99 p995
------------------------------------------------- -----------------------------
foo [WILDCARD] [WILDCARD]/iter[WILDCARD]([WILDCARD] … [WILDCARD]) [WILDCARD]

View file

@ -0,0 +1,6 @@
addEventListener("beforeunload", (e) => {
// The worker should be killed once benchmarks are done regardless of this.
e.preventDefault();
});
Deno.bench("foo", () => {});

View file

@ -0,0 +1,5 @@
running 1 test from [WILDCARD]/before_unload_prevent_default.ts
foo ... ok ([WILDCARD])
ok | 1 passed | 0 failed ([WILDCARD])

View file

@ -0,0 +1,6 @@
addEventListener("beforeunload", (e) => {
// The worker should be killed once tests are done regardless of this.
e.preventDefault();
});
Deno.test("foo", () => {});

View file

@ -498,12 +498,9 @@ async fn bench_specifier(
sender.send(BenchEvent::Result(desc.id, result))?; sender.send(BenchEvent::Result(desc.id, result))?;
} }
loop { // Ignore `defaultPrevented` of the `beforeunload` event. We don't allow the
if !worker.dispatch_beforeunload_event(located_script_name!())? { // event loop to continue beyond what's needed to await results.
break; worker.dispatch_beforeunload_event(located_script_name!())?;
}
worker.run_event_loop(false).await?;
}
worker.dispatch_unload_event(located_script_name!())?; worker.dispatch_unload_event(located_script_name!())?;
Ok(()) Ok(())
} }

View file

@ -1033,12 +1033,9 @@ pub async fn test_specifier(
sender.send(TestEvent::Result(desc.id, result, elapsed as u64))?; sender.send(TestEvent::Result(desc.id, result, elapsed as u64))?;
} }
loop { // Ignore `defaultPrevented` of the `beforeunload` event. We don't allow the
if !worker.dispatch_beforeunload_event(located_script_name!())? { // event loop to continue beyond what's needed to await results.
break; worker.dispatch_beforeunload_event(located_script_name!())?;
}
worker.run_event_loop(false).await?;
}
worker.dispatch_unload_event(located_script_name!())?; worker.dispatch_unload_event(located_script_name!())?;
if let Some(coverage_collector) = coverage_collector.as_mut() { if let Some(coverage_collector) = coverage_collector.as_mut() {