mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
fix(test): handle dispatched exceptions from test functions (#18853)
Fixes #18852.
This commit is contained in:
parent
d043a6d72c
commit
03132e19da
8 changed files with 98 additions and 72 deletions
|
@ -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",
|
||||
|
|
23
cli/tests/testdata/test/report_error.out
vendored
Normal file
23
cli/tests/testdata/test/report_error.out
vendored
Normal 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
|
6
cli/tests/testdata/test/report_error.ts
vendored
Normal file
6
cli/tests/testdata/test/report_error.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
Deno.test("foo", () => {
|
||||
reportError(new Error("foo"));
|
||||
console.log(1);
|
||||
});
|
||||
|
||||
Deno.test("bar", () => {});
|
|
@ -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)?;
|
||||
|
|
|
@ -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>() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue