Mocha async timeout precedence between global configuration and per-test overrides in ESM modules
0 reputation · 30 Dec 2021, 21:00 UTC
Timeout Configuration Precedence
Mocha 8+ introduced ESM module support that altered how asynchronous tests handle unhandled rejections and timeout enforcement. The framework applies a default 2000 ms timeout globally, while allowing per-suite and per-test overrides via this.timeout() or the --timeout CLI flag. The slow() threshold (default 75% of timeout) influences reporting but not failure behavior.
Uncertainty in Override Interaction
Documentation indicates that global timeout changes may affect test isolation if not properly scoped, and that the --timeout flag must precede test files in some versions. However, the exact precedence order when multiple configuration layers coexist—global default, CLI flag, suite-level this.timeout(), and test-level this.timeout()—remains underspecified for async/await tests in ESM contexts. Node.js version differences further complicate unhandled rejection handling during timeout expiration.
What is the documented precedence order for timeout values across global, CLI, suite, and test levels when using async/await in ESM modules? Does a test-level this.timeout() call reliably override a CLI-provided --timeout value? How do unhandled rejections interact with timeout expiration across Node.js 18, 20, and 22?