mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(test): dispatch load event before tests are run (#11708)
This commit is contained in:
parent
2ca454b402
commit
d1fe03d677
4 changed files with 38 additions and 10 deletions
|
@ -49,6 +49,12 @@ itest!(fail {
|
|||
output: "test/fail.out",
|
||||
});
|
||||
|
||||
itest!(load_unload {
|
||||
args: "test test/load_unload.ts",
|
||||
exit_code: 0,
|
||||
output: "test/load_unload.out",
|
||||
});
|
||||
|
||||
itest!(doc {
|
||||
args: "test --doc --allow-all test/doc.ts",
|
||||
exit_code: 1,
|
||||
|
|
6
cli/tests/testdata/test/load_unload.out
vendored
Normal file
6
cli/tests/testdata/test/load_unload.out
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
Check [WILDCARD]/test/load_unload.ts
|
||||
running 1 test from [WILDCARD]/test/load_unload.ts
|
||||
test test ... ok ([WILDCARD])
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
|
||||
|
22
cli/tests/testdata/test/load_unload.ts
vendored
Normal file
22
cli/tests/testdata/test/load_unload.ts
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
let interval: number | null = null;
|
||||
addEventListener("load", () => {
|
||||
if (interval) {
|
||||
throw new Error("Interval is already set");
|
||||
}
|
||||
|
||||
interval = setInterval(() => {}, 0);
|
||||
});
|
||||
|
||||
addEventListener("unload", () => {
|
||||
if (!interval) {
|
||||
throw new Error("Interval was not set");
|
||||
}
|
||||
|
||||
clearInterval(interval);
|
||||
});
|
||||
|
||||
Deno.test("test", () => {
|
||||
if (!interval) {
|
||||
throw new Error("Interval was not set");
|
||||
}
|
||||
});
|
|
@ -16,7 +16,6 @@ use deno_core::futures::future;
|
|||
use deno_core::futures::stream;
|
||||
use deno_core::futures::FutureExt;
|
||||
use deno_core::futures::StreamExt;
|
||||
use deno_core::located_script_name;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
|
@ -221,6 +220,8 @@ pub async fn test_specifier(
|
|||
test_source
|
||||
.push_str("await new Promise(resolve => setTimeout(resolve, 0));\n");
|
||||
|
||||
test_source.push_str("window.dispatchEvent(new Event('load'));\n");
|
||||
|
||||
test_source.push_str(&format!(
|
||||
"await Deno[Deno.internal].runTests({});\n",
|
||||
json!({
|
||||
|
@ -230,6 +231,8 @@ pub async fn test_specifier(
|
|||
}),
|
||||
));
|
||||
|
||||
test_source.push_str("window.dispatchEvent(new Event('unload'));\n");
|
||||
|
||||
let test_file = File {
|
||||
local: test_module.to_file_path().unwrap(),
|
||||
maybe_types: None,
|
||||
|
@ -266,20 +269,11 @@ pub async fn test_specifier(
|
|||
None
|
||||
};
|
||||
|
||||
worker.execute_script(
|
||||
&located_script_name!(),
|
||||
"window.dispatchEvent(new Event('load'))",
|
||||
)?;
|
||||
|
||||
worker.execute_module(&test_module).await?;
|
||||
|
||||
worker
|
||||
.run_event_loop(maybe_coverage_collector.is_none())
|
||||
.await?;
|
||||
worker.execute_script(
|
||||
&located_script_name!(),
|
||||
"window.dispatchEvent(new Event('unload'))",
|
||||
)?;
|
||||
|
||||
if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
|
||||
worker
|
||||
|
|
Loading…
Reference in a new issue