Running @angular/build:unit-test with `--include=` should only compile the included tests
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 68/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- angular, typescript
研究方向
先從 @angular/build:unit-test executor 和 angular.json 中的測試設定開始,接著比較 --include 的處理方式與 libs/ui-components/tsconfig.spec.json 中的 include 模式。使用提供的 yarn ng test 命令,並驗證只有選取的 spec 及其相依項會被編譯,如此一來,無關測試中的錯誤就不會再阻擋它,也能縮短建置時間。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- TypeScript
- 星號
- 27k
- 分支
- 11.8k
- 平均合併
- 16 小時 35 分鐘
- 30 天內合併 PR
- 176
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
angular/angular-cli 的其他 Issue
-
area: @angular/build gemini-triaged
難度 2/5 1-3 小時 新手友好度 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
難度 2/5 1-3 小時 新手友好度 72/100
angular/angular-cli#33055 · 1 則留言 · 3 個 reaction ·
-
area: @angular/build gemini-triaged
難度 4/5 3-5 天 新手友好度 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 已指派 1 人 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 已指派 1 人 ·
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
S: triage
難度 1/5 1 小時以內 新手友好度 85/100
-
難度 2/5 1-3 小時 新手友好度 76/100
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) 未關閉
難度 2/5 1-3 小時 新手友好度 90/100
snapshot-labs/stamp#666 ·
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
GauravKarakoti/SecureFlow#1070 · 1 則留言 ·
-
feature:Languages/Translations good first issue ready Web
難度 2/5 1-3 小時 新手友好度 72/100
digitalfabrik/integreat-app#4394 ·