Guide
Diagnosing Karma Test Runner Failures with ChromeHeadless and autoWatch
A step‑by‑step diagnostic guide for common Karma failures with ChromeHeadless and autoWatch, including symptom tables, ordered checks, fixes, and escalation paths.
Published by Tasadduq Burney
16 Oct 2025, 17:56 UTC
4 min38.4K views0

Recognizable Condition
When running Karma tests you may see one of the following symptoms:
- Karma reports "Chrome could not be launched" even though ChromeHeadless is installed.
- The test runner hangs or restarts repeatedly when
autoWatchis enabled, never exiting. - No test results appear in the console or CI logs.
- Karma aborts with "Failed to load script" messages during test compilation.
- The server starts but no browsers attach, yielding a "No browsers started" error.
- Tests pass locally but fail in CI due to stale cache or version mismatches.
Cause & Diagnostic Table
| Symptom | Likely Cause |
|---|---|
| Chrome could not be launched | Chrome binary path mis‑resolved or missing from PATH; architecture mismatch. |
| Tests hang/restart with autoWatch | Stale watched files or a background process keeping the watcher active. |
| No results emitted | Reporter missing, misnamed, or throwing an error; custom reporter not tested. |
| Failed to load script | Preprocessor (webpack/Babel) syntax error or unsupported language feature. |
| No browsers started | Browser launcher missing or misnamed in browsers array. |
| CI‑only failures | Stale Karma cache, outdated test harness, or version mismatch with Angular CLI. |
Ordered Checks
- Verify Chrome binary location:
Look for a log line similar to# Run in the project root which chrome # or which google-chrome karma start --single-run --log-level=debugChrome binary at /usr/bin/google-chrome. If the path differs from thewhichoutput, correct it inkarma.conf.jsundercustomLaunchersor ensure the binary is onPATH. - Check autoWatch behavior:
If the process does not exit, examine the debug log for repeatedkarma start --single-runWatchingmessages. Temporarily setautoWatch: falseand re‑run to confirm the hang is watcher‑related. - Inspect reporter configuration:
Run the tests again. If output appears, the original custom reporter is faulty; fix or remove it.# In karma.conf.js reporters: ['progress'] # replace custom reporter temporarily - Validate preprocessor pipeline:
Ensure no compilation errors are reported before starting Karma.# Example for webpack npm run build # or the script that invokes webpack/babel - Confirm browser launcher presence:
Run# In karma.conf.js browsers: ['ChromeHeadless']karma start --browsers ChromeHeadless. If you still see "No browsers started", verify that thekarma-chrome-launcherpackage is installed and that the launcher name matches exactly. - Check for stale cache or version mismatches:
If using Angular, ensurerm -rf node_modules/.cache/karma npm install # reinstalls exact versions karma start --single-run@angular-devkit/build-angularversion matches the Angular CLI version specified inpackage.json.
Fixes Tied to Findings
- Chrome launch failure – Add or correct the
chromeBinaryproperty in a custom launcher:
Ensure the binary path is absolute ifcustomLaunchers: { ChromeHeadless: { base: 'ChromeHeadless', flags: ['--no-sandbox'] } }PATHcannot be relied upon. - autoWatch hang – Disable watcher in CI and use a file‑watch exclusion list:
autoWatch: process.env.CI ? false : true, exclude: ['node_modules/**', 'dist/**'] - Missing reporter output – Replace the custom reporter with a known‑good one or fix its implementation; verify locally before committing.
- Preprocessor syntax error – Update webpack/Babel config to support the language features used in test files (e.g., add
@babel/preset-envor appropriate loader). - No browsers started – Install the launcher if missing:
Then ensure the launcher name is exactlynpm install --save-dev karma-chrome-launcherChromeHeadlessin thebrowsersarray. - CI‑only failures – Clear Karma cache and align dependency versions; consider adding a
ciscript that setsautoWatch: falseand runskarma start --single-run.
Escalation Criteria
- If after applying the above checks the Chrome binary still cannot be launched, verify the OS architecture (e.g., ARM vs x86) and obtain a compatible Chrome build.
- When autoWatch continues to cause infinite loops despite
autoWatch: false, inspect for external processes that may be touching watched files (e.g., IDE indexers) and consider narrowing the watched glob. - If a custom reporter is required and continues to fail after local testing, capture its error output and treat it as a separate bug; fallback to the built‑in reporters for CI until resolved.
- For persistent preprocessor failures, run the build step in isolation and consult the respective tool’s documentation; if the error is unrelated to Karma, address it in the webpack/Babel configuration.
- Should the "No browsers started" error persist after confirming launcher installation, check for SELinux/AppArmor or container restrictions that block the Chrome sandbox; adjust security policies or run with
--no-sandboxas a temporary measure.
Verification
After each fix, run the following command to confirm the symptom is resolved:
karma start --single-run --log-level=info
Look for:
- A line indicating Chrome launched successfully.
- The test runner exiting with a summary (e.g.,
Chrome Headless 115.0.0.0 (Linux 0.0.0): Executed 12 of 12 SUCCESS). - No hanging or repeated restart messages.
If the output matches expectations, the issue is considered resolved for the current environment.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.