From 03132e19da6c8e34e8100c6a57cd911b43900950 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 27 Apr 2023 13:40:03 +0100 Subject: fix(test): handle dispatched exceptions from test functions (#18853) Fixes #18852. --- cli/tests/integration/test_tests.rs | 6 ++++++ cli/tests/testdata/test/report_error.out | 23 +++++++++++++++++++++++ cli/tests/testdata/test/report_error.ts | 6 ++++++ 3 files changed, 35 insertions(+) create mode 100644 cli/tests/testdata/test/report_error.out create mode 100644 cli/tests/testdata/test/report_error.ts (limited to 'cli/tests') 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", () => {}); -- cgit v1.2.3