Skip to content

@angular/builder:unit-test does not serve static assets at the correct output path #31388

@wein2011

Description

@wein2011

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

21.0.0-next.2 (bug shows up with 21.0.0-next.3)

Description

When testing the new Vitest unit-test features in 21.0.0-next.6, I noticed a new issue when serving static assets.

One of the static assets is 'src/assets/image/add-0.0.1.svg'.

The angular.json configuration is:

"build": {
  ...
  "assets": ["src/assets"],
  ...
}

or

"build": {
  ...
  "assets": [{
    "glob": "**/*",
    "input": "src/assets",
    "output": "/assets"
  }],
  ...
}

When serving the application with 'ng server', the static assets is served correctly at:

http://localhost:4200/assets/image/add-0.0.1.svg

However, when serving the application with 'ng test --browsers Chromium --watch', the static assets is NOT served at:

http://localhost:63315/assets/image/add-0.0.1.svg

Instead the static assets is only served at:

http://localhost:63315/src/assets/image/add-0.0.1.svg

It seems like that the unit-test build does not take the complete 'assets' configuration into account.

This still worked in 21.0.0-next.2 as well as 20.2.0.

Minimal Reproduction

  1. Add a static assets such as 'src/assets/image/add-0.0.1.svg'.

  2. Add the assets configuration to angular.json:

"build": {
  ...
  "assets": ["src/assets"],
  ...
}
  1. Run the application with 'ng test --browsers Chromium --watch'.

  2. Check if static assets is served at:

http://localhost:63315/assets/image/add-0.0.1.svg

Exception or Error


Your Environment

Angular CLI       : 21.0.0-next.6
Node.js           : 22.18.0
Package Manager   : npm 10.9.3
Operating System  : win32 x64

┌───────────────────────────┬───────────────┐
│ Package                   │ Version       │
├───────────────────────────┼───────────────┤
│ @angular/build            │ 21.0.0-next.6 │
│ @angular/cli              │ 21.0.0-next.6 │
│ @angular/common           │ 21.0.0-next.6 │
│ @angular/compiler         │ 21.0.0-next.6 │
│ @angular/compiler-cli     │ 21.0.0-next.6 │
│ @angular/core             │ 21.0.0-next.6 │
│ @angular/forms            │ 21.0.0-next.6 │
│ @angular/platform-browser │ 21.0.0-next.6 │
│ @angular/router           │ 21.0.0-next.6 │
│ rxjs                      │ 7.8.2         │
│ typescript                │ 5.9.3         │
└───────────────────────────┴───────────────┘

Anything else relevant?

No response

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