fix(test): handle dispatched exceptions from test functions (#18853)

Fixes #18852.
This commit is contained in:
Nayeem Rahman 2023-04-27 13:40:03 +01:00 committed by GitHub
parent d043a6d72c
commit 03132e19da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 98 additions and 72 deletions

View file

@ -425,6 +425,12 @@ itest!(uncaught_errors {
exit_code: 1,
});
itest!(report_error {
args: "test --quiet test/report_error.ts",
output: "test/report_error.out",
exit_code: 1,
});
itest!(check_local_by_default {
args: "test --quiet test/check_local_by_default.ts",
output: "test/check_local_by_default.out",

View file

@ -0,0 +1,23 @@
running 2 tests from [WILDCARD]/report_error.ts
foo ...
Uncaught error from [WILDCARD]/report_error.ts FAILED
foo ... cancelled (0ms)
bar ... cancelled (0ms)
ERRORS
[WILDCARD]/report_error.ts (uncaught error)
error: Error: foo
reportError(new Error("foo"));
^
at [WILDCARD]/report_error.ts:2:15
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.
FAILURES
[WILDCARD]/report_error.ts (uncaught error)
FAILED | 0 passed | 3 failed ([WILDCARD])
error: Test failed

View file

@ -0,0 +1,6 @@
Deno.test("foo", () => {
reportError(new Error("foo"));
console.log(1);
});
Deno.test("bar", () => {});

View file

@ -489,14 +489,7 @@ async fn bench_specifier(
}))?;
for (desc, function) in benchmarks {
sender.send(BenchEvent::Wait(desc.id))?;
let promise = {
let scope = &mut worker.js_runtime.handle_scope();
let cb = function.open(scope);
let this = v8::undefined(scope).into();
let promise = cb.call(scope, this, &[]).unwrap();
v8::Global::new(scope, promise)
};
let result = worker.js_runtime.resolve_value(promise).await?;
let result = worker.js_runtime.call_and_await(&function).await?;
let scope = &mut worker.js_runtime.handle_scope();
let result = v8::Local::new(scope, result);
let result = serde_v8::from_v8::<BenchResult>(scope, result)?;

View file

@ -997,14 +997,7 @@ pub async fn test_specifier(
}
sender.send(TestEvent::Wait(desc.id))?;
let earlier = SystemTime::now();
let promise = {
let scope = &mut worker.js_runtime.handle_scope();
let cb = function.open(scope);
let this = v8::undefined(scope).into();
let promise = cb.call(scope, this, &[]).unwrap();
v8::Global::new(scope, promise)
};
let result = match worker.js_runtime.resolve_value(promise).await {
let result = match worker.js_runtime.call_and_await(&function).await {
Ok(r) => r,
Err(error) => {
if error.is::<JsError>() {