Skip to content

@angular/build v21.2.0 breaks vitest stack traces #32680

@rosenthalj

Description

@rosenthalj

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

@angular/build v21.1.5

Description

Stack traces for failed angular vitest unit tests display incorrect file information when the stack trace involves multiple files.

Note: The line numbers displayed in the stack trace are correct but filenames (if multiple files are involved) will be incorrect

Minimal Reproduction

  1. ng new vitestStackTraceBug
  2. npm install -D @vitest/browser-playwright
  3. Add the following file: src/app/spec-helper.ts
export class SpecHelper {
   testMethod(value: unknown) {
      expect(value).toBeFalsy();
   }
}
  1. Update src/app/app.spec.ts:
import { TestBed } from '@angular/core/testing';
import { App } from './app';
+import { SpecHelper } from './spec-helper';

describe('App', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [App],
    }).compileComponents();
  });

  it('should create the app', () => {
    const fixture = TestBed.createComponent(App);
    const app = fixture.componentInstance;
+  expect(app).toBeTruthy();
    new SpecHelper().testMethod(app);
  });

  it('should render title', async () => {
    const fixture = TestBed.createComponent(App);
    await fixture.whenStable();
    const compiled = fixture.nativeElement as HTMLElement;
    expect(compiled.querySelector('h1')?.textContent).toContain('Hello, vitestStackTraceBug');
  });
});
  1. Run unit tests (vitest):
    Browser:
    ng test --browsers=chromium
    or
    Headless Browser:
    ng test --browsers=chromiumHeadless

The following annotated screenshot shows the bug when running with a headed browser:

Image

The following annotated screenshot shows the bug when running with a headless browser:

Image

Attached is the source code that reproduces this bug: vitestStackTraceBug.tar.gz

Exception or Error


Your Environment

Angular CLI       : 21.2.0
Angular           : 21.2.0
Node.js           : 22.17.0
Package Manager   : npm 10.9.2
Operating System  : darwin arm64

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

Anything else relevant?

Using @angular/build v21.1.5

Image

The following annotated screenshot shows the functionality working (v21.1.5) when running with a headed browser:

Image

The following annotated screenshot shows the functionality working (v21.1.5) when running with a headless browser:

Image

Attached is the v21.1.5 source code that works correctly: vitestStackTraceBug.v21.1.5.tar.gz
(same code, package.json was updated with 21.1.5)

Examining the Angular v21.2.0 changes, the regression bug may have been induced by the following commit:

0b49827

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions