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

Open Beginner friendly
#33,055 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
angular, typescript
Domain
cli, testing

Research direction

Start with packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts around lines 161-170, where the custom no-test-files check is described. Review how the test command passes runner options to Vitest, then verify a project with no test files succeeds through Vitest's passWithNoTests option while the default behavior remains unchanged.

Written by the indexing model from the issue text.

Description

area: @angular/cli gemini-triaged
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:

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:

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.
Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 21m
Merged PRs (30d)
170

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.