angular / angular/angular-cli

Allow tests to pass without any test files (e.g. via Vitest `passWithNoTests`)

Đang mở Phù hợp với người mới
#33,055 1 bình luận 3 reaction 0 người được giao Xem trên GitHub
area: @angular/cli gemini-triaged
Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
14 giờ 23 phút
Pull request đã merge (30 ngày)
162

Mô tả

### Command

test

### Description

Executing the **test** command on a project (app or lib) that does not have any test files (yet) will always lead to the following error message:

```txt
An exception occurred while getting runner-specific build options:
Error: No tests found matching the following patterns:
- Included: **/*.spec.ts, **/*.test.ts

Please check the 'test' target configuration in your project's 'angular.json' file.
```

However, many use cases exist where this behaviour is unintended. For example, a freshly generated project (even more so in a monorepo) will often start out without any real test cases defined, and it even may take some time for the first ones to be written. Even at this early point, though, I (as a developer) will usually want to already integrate test execution into a quality gate setup (like continuous integration).

Currently, the Angular CLI does not offer a way to allow the **test** command to succeed when no test files exist.

Related issue: https://github.com/nrwl/nx/issues/34241

### Describe the solution you'd like

The most pragmatic solution would probably be:

- Remove the custom Angular CLI check for test files, see: https://github.com/angular/angular-cli/blob/5adc92541433be23fc2246db5a199cf5c0dc9e67/packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts#L161-L170
- Instead, rely on Vitest and its `passWithNoTests` option - which is `false` by default, so no breaking change is to be expected (besides a different log message)

### Describe alternatives you've considered

Alternatively:

- The Angular CLI **test** command could also expose its own option. This would however collide with the respective Vitest option and thus require conflict resolution / priority checks. Plus, skimming the source code leads me to believe that the Angular CLI is currently not actively loading any custom Vite config, just passing it on - so changes here would presumably affect multiple places.

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

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

Hướng nghiên cứu

Bắt đầu với packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts, khoảng dòng 161-170, nơi mô tả kiểm tra tùy chỉnh khi không có tệp kiểm thử. Xem lại cách lệnh kiểm thử truyền các tùy chọn của runner cho Vitest, sau đó xác minh rằng một dự án không có tệp kiểm thử sẽ thành công thông qua tùy chọn passWithNoTests của Vitest, trong khi hành vi mặc định vẫn không thay đổi.

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

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
cli, testing
Loại issue
Tính năng
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

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.