diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index a95590433ca1ad..96f08ac1fd34d0 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -792,6 +792,19 @@ async fn run_tests_for_worker_inner( } }; + // Check the result before we check for leaks + let result = { + let scope = &mut worker.js_runtime.handle_scope(); + let result = v8::Local::new(scope, result); + serde_v8::from_v8::(scope, result)? + }; + if matches!(result, TestResult::Failed(_)) { + fail_fast_tracker.add_failure(); + let elapsed = earlier.elapsed().as_millis(); + sender.send(TestEvent::Result(desc.id, result, elapsed as u64))?; + continue; + } + // Await activity stabilization if let Some(diff) = wait_for_activity_to_stabilize( worker, @@ -806,6 +819,7 @@ async fn run_tests_for_worker_inner( let (formatted, trailer_notes) = format_sanitizer_diff(diff); if !formatted.is_empty() { let failure = TestFailure::Leaked(formatted, trailer_notes); + fail_fast_tracker.add_failure(); let elapsed = earlier.elapsed().as_millis(); sender.send(TestEvent::Result( desc.id, @@ -816,12 +830,6 @@ async fn run_tests_for_worker_inner( } } - let scope = &mut worker.js_runtime.handle_scope(); - let result = v8::Local::new(scope, result); - let result = serde_v8::from_v8::(scope, result)?; - if matches!(result, TestResult::Failed(_)) { - fail_fast_tracker.add_failure(); - } let elapsed = earlier.elapsed().as_millis(); sender.send(TestEvent::Result(desc.id, result, elapsed as u64))?; } diff --git a/tests/specs/test/sanitizer_with_error/__test__.json b/tests/specs/test/sanitizer_with_error/__test__.json new file mode 100644 index 00000000000000..d92c3a31f0327a --- /dev/null +++ b/tests/specs/test/sanitizer_with_error/__test__.json @@ -0,0 +1,5 @@ +{ + "args": "test --quiet --reload main.js", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/test/sanitizer_with_error/main.js b/tests/specs/test/sanitizer_with_error/main.js new file mode 100644 index 00000000000000..38d0ea81e18970 --- /dev/null +++ b/tests/specs/test/sanitizer_with_error/main.js @@ -0,0 +1,6 @@ +Deno.test(function throws() { + // Leak + setTimeout(() => {}, 60_000); + // But the exception should mask the leak + throw new Error("Throws"); +}); diff --git a/tests/specs/test/sanitizer_with_error/main.out b/tests/specs/test/sanitizer_with_error/main.out new file mode 100644 index 00000000000000..2be6bf94669a4e --- /dev/null +++ b/tests/specs/test/sanitizer_with_error/main.out @@ -0,0 +1,18 @@ +running 1 test from ./main.js +throws ... FAILED ([WILDCARD]) + + ERRORS + +throws => ./main.js:1:6 +error: Error: Throws + throw new Error("Throws"); + ^ + at throws ([WILDCARD]/main.js:5:9) + + FAILURES + +throws => ./main.js:1:6 + +FAILED | 0 passed | 1 failed ([WILDCARD]) + +error: Test failed