Repository: deno
Issue: `deno test` exits prematurely if a test empties the event loop
Labels: bug,testing

If a test run via `Deno.test()` allows the event loop to empty, the test suite immediately fails without reporting the result of the test or any subsequent tests. 

The failure message is also somewhat confusing. It seems to be technically accurate, and makes sense if you understand what's happened. But confusing when you don't realise you've accidentally emptied the event loop, allowing it to halt and are trying to work out why your test is failing (actually not executing).

As a user of the test API, I'd expect in this situation that the test would hang until a timeout was triggered to fail the test.

Maybe an argument for tests having timeouts (per #11133)? E.g. if the test runner had a pending timer for the timeout, the event loop couldn't become empty while a test was executing.

This test module demonstrates the problem:
```ts
// empty_event_loop_test.ts
import { assertEquals } from "https://deno.land/std@0.118.0/testing/asserts.ts";

function someApi(flag: boolean) {
  return new Promise((resolve) => {
    if (flag) {
      resolve("foo");
    } else if (!"bug") {
      resolve("bar");
    } else {
      console.log("* accidentally not resolving promise");
    }
  });
}

Deno.test("someApi returns foo when flag is true", async () => {
  const result = await someApi(true);
  assertEquals(result, "foo");
});

Deno.test(
  "[premature-exit]: deno test terminates the whole suite when a test empties the event loop",
  async () => {
    // event loop exits while awaiting someApi's promise
    console.log("\n\nBefore await");
    const result = await someApi(false);
    // this never executes because result is never resolved
    console.log("After await");
    assertEquals(result, "bar");
  },
);

Deno.test("[premature-exit]: simplified example", () => {
  return new Promise(() => {});
});

Deno.test("This is never executes if a premature-exit example does", () => {});
```

The tests stop executing when the first `[premature-exit]` test runs:
```
$ deno test empty_event_loop_test.ts
running 4 tests from file:///private/tmp/empty_event_loop_test.ts
test someApi returns foo when flag is true ... ok (8ms)
test [premature-exit]: deno test terminates the whole suite when a test empties the event loop ...

Before await

* accidentally not resolving promise


test result: FAILED. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (35ms)

error: Promise resolution is still pending but the event loop has already resolved.
```
Final test executes as expected if no `[premature-exit]` tests run:
```
$ deno test empty_event_loop_test.ts --filter '/^someApi|never executes/'
running 2 tests from file:///private/tmp/empty_event_loop_test.ts
test someApi returns foo when flag is true ... ok (10ms)
test This is never executes if a premature-exit example does ... ok (6ms)

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out (164ms)
```
The simplified `[premature-exit]` also causes a premature exit:
```
$ deno test empty_event_loop_test.ts --filter '/\[premature-exit\]: simplified|never executes/'
running 2 tests from file:///private/tmp/empty_event_loop_test.ts
test [premature-exit]: simplified example ...
test result: FAILED. 0 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out (30ms)

error: Promise resolution is still pending but the event loop has already resolved.
```