`unit-test` builder resolves include paths relative to sourceRoot instead of project root, breaking secondary entry points tests

Abierto
#33,467 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
angular, typescript

Línea de trabajo

Empieza ejecutando la reproducción mínima con el builder @angular/build:unit-test e inspecciona cómo se resuelven sus patrones de inclusión de angular.json. Verifica el comportamiento con una biblioteca que contenga la ruta mostrada my-sub-package/**/*.spec.ts. Se considera terminado cuando los patrones se resuelven desde la raíz del proyecto y ng test descubre pruebas en puntos de entrada secundarios sin atravesar rutas mediante ../.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

angular/build:unit-test area: @angular/build
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

When using the @angular/build:unit-test builder in a library project that contains Secondary Entry Points (sub-packages), the builder incorrectly resolves the glob patterns defined in the include array (inside angular.json) relative to the project's sourceRoot (usually .../src) instead of the project's root.

Because the unit-test builder anchors include patterns to sourceRoot, it cannot discover test files located in secondary entry points unless developers use relative path traversal (for example, ../my-sub-package/**/*.spec.ts).

Minimal Reproduction

Create an Angular library project.
2. Generate a secondary entry point inside the library root (for example, projects/my-lib/my-sub-package/).
3. Add a unit test inside the secondary entry point:

projects/my-lib/my-sub-package/my-sub.spec.ts
  1. Configure the test target in angular.json using @angular/build:unit-test:

    {
      "options": {
        "include": [
          "**/*.spec.ts",
          "my-sub-package/**/*.spec.ts"
        ],
        "tsConfig": "projects/my-lib/tsconfig.spec.json"
      }
    }
    
  2. Run:

    ng test
    
Exception or Error

The builder should resolve the include patterns relative to the project's root, or otherwise recognize ng-packagr secondary entry points, allowing patterns such as:

{
  "include": [
    "**/*.spec.ts",
    "my-sub-package/**/*.spec.ts"
  ]
}

to correctly match test files located in:

projects/my-lib/my-sub-package/
Workaround

Currently, developers must escape the sourceRoot directory by using a parent path segment in angular.json:

{
  "options": {
    "include": [
      "**/*.spec.ts",
      "../my-sub-package/**/*.spec.ts"
    ],
    "tsConfig": "projects/my-lib/tsconfig.spec.json"
  }
}
Your Environment
_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI       : 22.0.4
Angular           : 22.0.2
Node.js           : 24.16.0
Package Manager   : npm 11.13.0
Operating System  : linux x64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations               │ 22.0.2            │ ^22.0.2           │
│ @angular/build                    │ 22.0.4            │ ^22.0.4           │
│ @angular/cli                      │ 22.0.4            │ ^22.0.4           │
│ @angular/common                   │ 22.0.2            │ ^22.0.2           │
│ @angular/compiler                 │ 22.0.2            │ ^22.0.2           │
│ @angular/compiler-cli             │ 22.0.2            │ ^22.0.2           │
│ @angular/core                     │ 22.0.2            │ ^22.0.2           │
│ @angular/forms                    │ 22.0.2            │ ^22.0.2           │
│ @angular/localize                 │ 22.0.2            │ ^22.0.2           │
│ @angular/platform-browser         │ 22.0.2            │ ^22.0.2           │
│ @angular/platform-browser-dynamic │ 22.0.2            │ ^22.0.2           │
│ @angular/router                   │ 22.0.2            │ ^22.0.2           │
│ @angular/service-worker           │ 22.0.2            │ ^22.0.2           │
│ ng-packagr                        │ 22.0.0            │ ^22.0.0           │
│ rxjs                              │ 7.8.2             │ ~7.8.2            │
│ typescript                        │ 6.0.3             │ ^6.0.3            │
│ vitest                            │ 4.1.9             │ ^4.1.9            │
│ zone.js                           │ 0.16.2            │ ^0.16.2           │
└───────────────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?

No response

Lenguaje dominante
TypeScript
Estrellas
27k
Forks
11.8k
Merge medio
16 h 21 min
PR fusionados (30 d)
170

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de angular/angular-cli

Todos los issues de angular/angular-cli

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.