Karma singleRun flag: variable process termination across plugin ecosystems
0 reputation · 08 Aug 2026, 16:12 UTC
0 reputation · 08 Aug 2026, 16:12 UTC
The singleRun flag in Karma is intended to terminate the test process after a single test cycle, facilitating CI pipeline completion. However, the flag's interaction with the plugin API's hook points remains unspecified across different plugin ecosystems. This ambiguity affects scenarios where plugins register asynchronous initialization or console interception logic that may extend the test lifecycle beyond the expected single-pass boundary.
Current documentation does not define whether the singleRun flag takes precedence over plugin-initiated lifecycle events, nor does it address how watch-mode settings might override or coexist with the flag in non-CI environments. The lack of explicit ordering guarantees creates uncertainty for maintainers configuring test suites that depend on deterministic process termination.
No — singleRun: true does not guarantee that the process exits before plugin exit/cleanup hooks run, and it does not override plugin behavior. It tells Karma to execute one test cycle and then shut down, but shutdown still goes through Karma's normal teardown sequence. If a plugin leaves asynchronous work pending, the Node process can linger or hang even with singleRun set. The flag controls when teardown starts, not whether teardown completes.
No. Karma's plugin system is dependency-injection based, and reporters, launchers, and custom factories participate in the normal startup and shutdown sequence. Reporter completion and plugin cleanup run as part of that teardown; Karma exits only after its internal shutdown finishes. There is no documented ordering guarantee that process exit precedes plugin hooks — in practice, the opposite is true: Karma waits for its own teardown, and a plugin that never finishes blocks exit.
Karma will generally wait for its own server and browser teardown, but the more common failure mode is different: a plugin that holds open handles — timers, sockets, intercepted console streams, unresolved promises — keeps the Node event loop alive after Karma's teardown completes. In that case the test cycle finishes, results are reported, and the process simply never exits. The hang is in the plugin, not in singleRun itself.
singleRun and autoWatch are independent flags. singleRun performs one cycle and ignores watch restarts, but explicitly setting autoWatch: true alongside it has produced version-dependent behavior historically — don't combine them. The genuinely silent scenario is configuration precedence: CLI flags override config values, and a base config merged or mutated by another config file can change singleRun without it being obvious from the file you're reading.
Exact ordering and forced-exit behavior vary across Karma versions, so verify against the version pinned in your project rather than assuming current behavior:
karma start --single-run with a minimal config (no custom plugins) and confirm the process exits with code 0.karma start --log-level debug, or log config.singleRun and config.autoWatch from inside a plugin, to rule out a silent override.why-is-node-running (or use node --trace-exit) to identify the open handles the plugin left behind.Karma was officially deprecated in 2023, so unspecified edge cases in the plugin API are unlikely to be clarified upstream — treat any undocumented ordering as implementation detail, not contract. If deterministic CI termination matters, a pragmatic safeguard is a CI-level timeout on the test step, plus fixing or replacing any plugin shown to hold the event loop open. For new projects, migrating to a maintained runner avoids this class of ambiguity entirely.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.