Skip to content
Latchkey

Angular "ng test" hangs in watch mode in CI

ng test defaults to watch mode: it runs the suite, then waits for file changes and never exits. In CI that means the step runs until the job timeout kills it. Disable watch and use a headless browser so the run exits with a status.

What this error means

The ng test step produces test results but never finishes; the job eventually fails with a timeout, or appears to hang after "Executed N of N".

ng test
Chrome Headless: Executed 42 of 42 SUCCESS (1.2 secs / 1.1 secs)
TOTAL: 42 SUCCESS
# ...step never exits, job times out

Common causes

Watch mode is on by default

Without --watch=false, karma stays running to watch for changes, so the process never returns control to CI.

A headed browser was requested on a headless runner

Requesting a non-headless browser also stalls, since no display exists to launch it.

How to fix it

Run non-watch and headless

Pass --watch=false and a headless browser so karma runs once, reports, and exits with a status code.

Terminal
npx ng test --watch=false --browsers=ChromeHeadless

Add a dedicated CI test script

Encode the CI flags in an npm script so every pipeline uses the same non-watch headless run.

package.json
"scripts": {
  "test:ci": "ng test --watch=false --browsers=ChromeHeadlessCI --code-coverage"
}

How to prevent it

  • Always pass --watch=false in CI test runs.
  • Use a headless browser launcher on runners.
  • Wrap the CI flags in a test:ci npm script.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →