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:
parent
675aa94d12
commit
434c80bd62
8 changed files with 40 additions and 12 deletions
|
@ -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,
|
||||||
|
|
|
@ -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();
|
||||||
|
|
7
cli/tests/testdata/bench/before_unload_prevent_default.out
vendored
Normal file
7
cli/tests/testdata/bench/before_unload_prevent_default.out
vendored
Normal 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]
|
6
cli/tests/testdata/bench/before_unload_prevent_default.ts
vendored
Normal file
6
cli/tests/testdata/bench/before_unload_prevent_default.ts
vendored
Normal 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", () => {});
|
5
cli/tests/testdata/test/before_unload_prevent_default.out
vendored
Normal file
5
cli/tests/testdata/test/before_unload_prevent_default.out
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
running 1 test from [WILDCARD]/before_unload_prevent_default.ts
|
||||||
|
foo ... ok ([WILDCARD])
|
||||||
|
|
||||||
|
ok | 1 passed | 0 failed ([WILDCARD])
|
||||||
|
|
6
cli/tests/testdata/test/before_unload_prevent_default.ts
vendored
Normal file
6
cli/tests/testdata/test/before_unload_prevent_default.ts
vendored
Normal 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", () => {});
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue