Skip to content

Commit

Permalink
fix(test): return error when awaiting unresolved promise (#7968)
Browse files Browse the repository at this point in the history
This commit fixes test runner by awaitning "Deno.runTests()" call,
which ensures proper error is returned when there's an unresolved
promise that's being awaited.
  • Loading branch information
bartlomieju authored Oct 14, 2020
1 parent e9f02c2 commit 12e700b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cli/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ pub fn render_test_file(
json!({ "failFast": fail_fast, "reportToConsole": !quiet, "disableLog": quiet })
};

let run_tests_cmd = format!(
"// @ts-ignore\nDeno[Deno.internal].runTests({});\n",
test_file.push_str("// @ts-ignore\n");

test_file.push_str(&format!(
"await Deno[Deno.internal].runTests({});\n",
options
);
test_file.push_str(&run_tests_cmd);
));

test_file
}
Expand Down
4 changes: 4 additions & 0 deletions cli/tests/deno_test_unresolved_promise.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Check [WILDCARD]
running 2 tests
test unresolved promise ... in promise
error: Module evaluation is still pending but there are no pending ops or dynamic imports. This situation is often caused by unresolved promise.
6 changes: 6 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,12 @@ itest!(deno_test_no_check {
output: "deno_test.out",
});

itest!(deno_test_unresolved_promise {
args: "test test_unresolved_promise.js",
exit_code: 1,
output: "deno_test_unresolved_promise.out",
});

#[test]
fn timeout_clear() {
// https://github.com/denoland/deno/issues/7599
Expand Down
15 changes: 15 additions & 0 deletions cli/tests/test_unresolved_promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Deno.test({
name: "unresolved promise",
fn() {
return new Promise((_resolve, _reject) => {
console.log("in promise");
});
},
});

Deno.test({
name: "ok",
fn() {
console.log("ok test");
},
});

0 comments on commit 12e700b

Please sign in to comment.