ng test does not run tests from new test files when watching

Open
#26,470 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, typescript
Domain
cli, testing

Research direction

Reproduce the behavior with the listed ng new, ng test, and ng g component widget commands, then trace the ng test watch flow that detects and recompiles the new test file. Compare the initial and restarted test runs; done means tests in newly added files execute during watching without restarting the process.

Written by the indexing model from the issue text.

Description

area: @angular-devkit/build-angular devkit/build-angular:karma freq1: low severity3: broken type: bug/fix
Command

test

Is this a regression?
  • Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was

No response

Description

While ng test is running and watching for changes, if you add a new test file, that file is detected and causes the tests to run again, but the tests in that new file are not included in the test run. To include the tests from the new file, you need to restart the ng test process.

Minimal Reproduction
  1. In a terminal, run:
ng new watch --skip-git --style css --ssr=false 
ng test
  1. Three tests are run.
  2. In a second terminal, run:
ng g component widget
  1. A new component is created with a test file that contains one test.
  2. The new test file is detected and the tests recompile.
  3. Only three tests are run.
  4. Add another test to the new component's test file.
  5. The change is detected and the tests recompile.
  6. Only three tests are run.
  7. Kill the ng test process.
  8. Run ng test again.
  9. Five tests are run.
Exception or Error

No response

Your Environment
_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 17.0.3
Node: 20.9.0
Package Manager: npm 10.1.0
OS: win32 x64

Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1700.3 (cli-only)
@angular-devkit/core         17.0.3 (cli-only)
@angular-devkit/schematics   17.0.3 (cli-only)
@schematics/angular          17.0.3 (cli-only)
Anything else relevant?

Here's a screen recording to help explain what I'm seeing.
ng-test-watch

Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.