Skip to content

new code is ignored after compilation error in vitest test #32122

@jnizet

Description

@jnizet

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 running ng test(in watch mode), if I introduce a compilation error in the test and save, the code is recompiled and the terminal shows me the compilation error. Until now, everything is fine.

Then, if I fix the error, make another change that should make the test fail, and save, then the terminal shows me the successful output of the recompilation, but the test is not re-executed. I would expect the test to be re-executed.

And if I type a in the terminal to rerun the tests, the test passes instead of failing, thus giving a false positive.

I need to re-run ng test to take the new code of the test into account.

Minimal Reproduction

  • npx @angular/cli new clirepro
  • accept the default options (CSS, no AI)
  • cd clirepro
  • ng test
  • open an editor and edit the sc/app/app.spec.ts file
  • replace compiled.querySelector( by compiled.querySelecto( then save
  • observe the compilation error in the terminal (expected): OK
  • replace compiled.querySelecto( by compiled.querySelector(, and also 'Hello, clirepro' by 'Hello, clirepro2', then save
  • observe the successful compilation result in the terminal, but no test rerun: KO
  • type a in the terminal to run the tests again
  • observe that all tests pass even though it should fail, since the h1 does not have the text 'Hello, clirepro2': KO
  • type Ctrl-C in the terminal
  • ng test: observe that the test now fails.

Exception or Error


Your Environment

Angular CLI       : 21.0.3
Angular           : 21.0.5
Node.js           : 22.18.0
Package Manager   : npm 10.9.3
Operating System  : darwin x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.0.3            │ ^21.0.0           │
│ @angular/cli              │ 21.0.3            │ ^21.0.0           │
│ @angular/common           │ 21.0.5            │ ^21.0.0           │
│ @angular/compiler         │ 21.0.5            │ ^21.0.0           │
│ @angular/compiler-cli     │ 21.0.5            │ ^21.0.0           │
│ @angular/core             │ 21.0.5            │ ^21.0.0           │
│ @angular/forms            │ 21.0.5            │ ^21.0.0           │
│ @angular/platform-browser │ 21.0.5            │ ^21.0.0           │
│ @angular/router           │ 21.0.5            │ ^21.0.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.0.15            │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions