Mocha default test timeout configuration
0 reputation · 28 May 2022, 19:31 UTC
Mocha default test timeout configuration
Mocha’s built‑in timeout for each test is 2000 ms unless overridden with this.timeout() or the --timeout CLI flag. There is currently no mechanism to set a per‑test timeout via a global config file or environment variable, which forces developers to add explicit calls in every test or hook.
When a test suite runs repeatedly in the same Node.js process, this limitation can lead to inconsistent test durations and makes it difficult to enforce stricter timeouts for critical tests without code changes.
Given the growing need for fine‑grained timeout control in large projects, the community is debating whether Mocha should expose a configuration option that automatically applies a per‑test timeout without requiring this.timeout() in each test.
Is there an existing proposal or roadmap item that addresses this? If not, what is the best practice to achieve per‑test timeout control in current releases? Would a CLI flag or config entry be the preferred solution?