Running @angular/build:unit-test with `--include=` should only compile the included tests

Đang mở
#34,089 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
angular, typescript

Hướng nghiên cứu

Bắt đầu với executor @angular/build:unit-test và cấu hình test trong angular.json, sau đó so sánh cách --include được xử lý với các pattern include trong libs/ui-components/tsconfig.spec.json. Sử dụng lệnh yarn ng test được cung cấp và xác minh rằng chỉ spec được chọn cùng các dependency của nó được biên dịch, để các lỗi test không liên quan không còn chặn nó và thời gian build được rút ngắn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

angular/build:unit-test area: @angular/build gemini-triaged
Command

test

Is this a regression?

No, it has been present since the @angular/build:unit-test builder was created.

Description

When I run:

yarn ng test ui-components --include=libs/ui-components/shortcuts/src/ShortcutEventsPlugin.spec.ts --watch=false

with angular.json config:

    "ui-components": {
      "projectType": "library"
      },
      "root": "libs/ui-components",
      "sourceRoot": "libs/ui-components",
      "prefix": "ui",
      "architect": {
        "build": {
          "builder": "@angular/build:ng-packagr",
          "options": {
            "project": "libs/ui-components/ng-package.json",
            "tsConfig": "libs/ui-components/tsconfig.lib.json"
          }
        },
        "test": {
          "builder": "@angular/build:unit-test",
          "options": {
            "buildTarget": "ui-components:build",
            "include": [
              "**/*.spec.ts"
            ],
            "tsConfig": "libs/ui-components/tsconfig.spec.json",
            "runnerConfig": "libs/ui-components/vitest.config.ts"
          }
        }
      }
    }

the @angular/build:unit-test executor (re)compiles all test files (**/*.spec.ts) in the library and those files' dependencies, even though only the included files are needed for the tests that are being run.

This creates 2 problems, aside from being wasteful:

  • This slows down our test/fix loops by a factor of about 2 relative to just compiling the included files, though obviously the speedup depends on the size of the project and other things
  • Compile errors in other tests prevent a developer from being able to run the tests they're working on

We use single file testing extensively during development, and we also have agent instructions to run tests with --include, so this causes significant problems for us.

Minimal Reproduction

In a larger project using @angular/build:unit-test, pick a single test file to run using --include, and run it:

yarn ng test (my-project) --include=(repo path to spec file) --watch=false

And note that mount of time building before running the test. You can also edit another test file in the project to break compilation, and note that you cannot run the first test file.

Then, edit the tsconfig.json.spec, replacing the wildcard patterns with the path to the file(s) being tested. Eg change:

// libs/ui-components/tsconfig.spec.json 
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts",
    "**/*.*tests.ts"
  ],

to

  "include": [
    "shortcuts/src/ShortcutEventsPlugin.spec.ts",
    // "**/*.spec.ts",
    // "**/*.d.ts",
    // "**/*.*tests.ts"
  ],

And re-run the test command with --include. Notice the reduced time building (Eg I see 12s -> 4s) before the tests are run, and also that compile errors in other tests don't block running a test.

NOTE: The performance impact of this behavioral bug increases with the size of the project, so it's not really feasible to create a minimal repro for that. However if you need a minimal repro repo showing that single file tests can't be run when there is a compile error in another test, I can provide one.

Your Environment
Angular CLI       : 22.0.8
Angular           : 22.0.8
Node.js           : 24.16.0
Package Manager   : yarn 4.18.0
Operating System  : win32 x64

┌────────────────────────────┬───────────────────┬───────────────────┐
│ Package                    │ Installed Version │ Requested Version │
├────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/core       │ 22.0.8            │ catalog:          │
│ @angular-devkit/schematics │ 22.0.8            │ catalog:          │
│ @angular/animations        │ 22.0.8            │ catalog:          │
│ @angular/build             │ 22.0.8            │ catalog:          │
│ @angular/cdk               │ 22.0.6            │ catalog:          │
│ @angular/cli               │ 22.0.8            │ catalog:          │
│ @angular/common            │ 22.0.8            │ catalog:          │
│ @angular/compiler          │ 22.0.8            │ catalog:          │
│ @angular/compiler-cli      │ 22.0.8            │ catalog:          │
│ @angular/core              │ 22.0.8            │ catalog:          │
│ @angular/forms             │ 22.0.8            │ catalog:          │
│ @angular/language-service  │ 22.0.8            │ catalog:          │
│ @angular/platform-browser  │ 22.0.8            │ catalog:          │
│ @angular/router            │ 22.0.8            │ catalog:          │
│ @schematics/angular        │ 22.0.8            │ catalog:          │
│ ng-packagr                 │ 22.0.2            │ catalog:          │
│ rxjs                       │ 7.8.2             │ catalog:          │
│ typescript                 │ 6.0.3             │ catalog:          │
│ vitest                     │ 4.1.8             │ catalog:          │
└────────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?

No response

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 35 phút
Pull request đã merge (30 ngày)
176

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.