#4834·mocha

Bug: `--timeout 0` does not disable timeouts

Author: bdcarrCreated Feb 24, 2022Updated Sep 17, 2026
Labelstype: bugstatus: accepting prssemver-major

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

I ran a mocha test using IntelliJ's debugger, which automatically sets --timeout 0. Left it paused for several minutes while looking at something, and when I resumed it, it timed out.

Steps to Reproduce

  1. Create a test script containing a single describe() and a single it() (you can do more, this is just a simple example)
  2. Inside the describe(), put this.timeout(T) (I haven't tried with the timeout() call inside the it(), not sure if behaviour changes)
  3. Ensure somehow that the it() will take longer than T to run: set a breakpoint, or add code that will take longer than that
  4. Run the test with --timeout 0

Working example

  1. Check out https://github.com/bdcarr/mocha-timeout-bug/tree/main
  2. cd newversion
  3. npm install
  4. npm run test

There's also an oldversion folder which contains the same test script, but the package.json is set to use [email protected], which is the last version where this issue doesn't occur. I checked with v8.0.0 and the issue occurs.

Expected behavior: No matter how long the test takes, it will not time out if run with --timeout 0

Actual behavior: The test times out after T milliseconds

2022-02-25 10-35-05

Reproduces how often: 100%

Versions

  • The output of mocha --version and node_modules/.bin/mocha --version: No global install. Issue reproduced on v8.0.0 and v9.2.1. Issue does not occur on v7.2.1.
  • The output of node --version: v14.9.0
  • Your operating system
    • name and version: MacOS 12.2.1
    • architecture (32 or 64-bit): 64-bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): zsh v5.8
  • Any third-party Mocha-related modules (and their versions): n/a
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): n/a, straight NodeJS with no imports