summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/integration/test_tests.rs6
-rw-r--r--cli/tests/testdata/test/report_error.out23
-rw-r--r--cli/tests/testdata/test/report_error.ts6
-rw-r--r--cli/tools/bench.rs9
-rw-r--r--cli/tools/test.rs9
5 files changed, 37 insertions, 16 deletions
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index 0e1a39deb..223c02e24 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -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",
diff --git a/cli/tests/testdata/test/report_error.out b/cli/tests/testdata/test/report_error.out
new file mode 100644
index 000000000..698550f97
--- /dev/null
+++ b/cli/tests/testdata/test/report_error.out
@@ -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
diff --git a/cli/tests/testdata/test/report_error.ts b/cli/tests/testdata/test/report_error.ts
new file mode 100644
index 000000000..56b6db26c
--- /dev/null
+++ b/cli/tests/testdata/test/report_error.ts
@@ -0,0 +1,6 @@
+Deno.test("foo", () => {
+ reportError(new Error("foo"));
+ console.log(1);
+});
+
+Deno.test("bar", () => {});
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs
index 962b1ac17..5f467bc6e 100644
--- a/cli/tools/bench.rs
+++ b/cli/tools/bench.rs
@@ -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)?;
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 268f3b4b9..62a104733 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -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>() {