Skip to content

Timeout does not function if test is writing to the console #3373

Closed
@mdouglass

Description

@mdouglass

Please provide details about:

  • What you're trying to do
    I have a test which is writing debug logs to the console but not making any asserts. The timeout on that test is triggering that the test failed, but not actually stopping the test run so ava never exits.

Timeouts can also be set individually for each test. These timeouts are reset each time an assertion is made. The test fails if it takes more than ms for an assertion to be made or the test to complete.

  • What happened
$ npm test will-not-stop.js

> test
> ava will-not-stop.js


0s
1s
2s
3s
4s
  ✘ [fail]: will not stop stop after 5s
5s
6s
7s
...
62s
^C  
  ✘ Exiting due to SIGINT

  Failed to exit when running will-not-stop.js

  ─

  will not stop

  Error: stop after 5s

  Error: stop after 5s
      at Timeout.<anonymous> (file:///Users/matthew/spikes/repro-ava-timeout/node_modules/ava/lib/test.js:439:24)
      at listOnTimeout (node:internal/timers:594:17)
      at process.processTimers (node:internal/timers:529:7)

  ─

  1 test failed
  • What you expected to happen
    I expected the test to exit after it was marked as having failed, as in this example:
$ npm test will-stop.js

> test
> ava will-stop.js


  ✘ [fail]: will stop stop after 5s
  
  ✘ Timed out while running tests

  Failed to exit when running will-stop.js

  ─

  will stop

  Error: stop after 5s

  Error: stop after 5s
      at Timeout.<anonymous> (file:///Users/matthew/spikes/repro-ava-timeout/node_modules/ava/lib/test.js:439:24)
      at listOnTimeout (node:internal/timers:594:17)
      at process.processTimers (node:internal/timers:529:7)

  ─

  1 test failed

Sample Code:

  1. Run npm init ava to create a skeleton project (done on 04/03/2025, ava v6.2.0)
  2. Add will-not-stop.js
import test from "ava";

test("will not stop", async (t) => {
  t.timeout(5_000, "stop after 5s");
  for (let i = 0; ; ++i) {
    console.log(`${i}s`);
    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
});
  1. Add will-stop.js (same as will-not-stop but with the write call commented out)
import test from "ava";

test("will not stop", async (t) => {
  t.timeout(5_000, "stop after 5s");
  for (let i = 0; ; ++i) {
    // console.log(`${i}s`);
    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcurrent functionality does not work as desiredscope:internals

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions