Skip to content

fix(@angular/build): allow ng test to pass with no test files via Vitest - #34597

Closed
ant1quar wants to merge 1 commit into
angular:mainfrom
ant1quar:fix/33055-pass-with-no-tests
Closed

ant1quar wants to merge 1 commit into
angular:mainfrom
ant1quar:fix/33055-pass-with-no-tests

Conversation

@ant1quar

Copy link
Copy Markdown

Summary

  • Remove the Vitest runner's early error when test discovery finds zero files, so execution reaches Vitest instead of failing during build-option setup.
  • Vitest's default passWithNoTests: false preserves existing failure behavior; enabling passWithNoTests in runnerConfig allows CI to succeed on projects without specs yet.

Fixes #33055

Test plan

  • pnpm bazel test //packages/angular/build:unit-test_integration_tests --test_filter='*no test files*'
  • Added integration tests for default failure and passWithNoTests: true via runnerConfig

Made with Cursor

Remove the unit-test builder pre-check that failed before Vitest ran so
passWithNoTests in runner config can succeed in CI when no specs exist yet.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the hardcoded error thrown when no test files are found in the Vitest builder options, allowing Vitest's native configuration (such as 'passWithNoTests') to dictate the outcome. Additionally, a new test suite has been introduced to verify that the builder correctly fails when no tests are discovered without 'passWithNoTests' enabled, and succeeds when the option is enabled in the runner configuration. I have no feedback to provide.

@alan-agius4

alan-agius4 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @ant1quar, thank you for putting together this pull request and for wanting to improve the Vitest integration!

In the Angular CLI, requiring test files to be present during ng test is an intentional safety guarantee. Failing when no matching test files are discovered prevents false positive CI runs, for instance when glob patterns are mistyped in the include option or directory structures are refactored, which could otherwise silently pass without running any tests.

If a project or library does not yet have unit tests, the recommended practice in an Angular workspace is to not configure or invoke the test target for that project rather than running an empty test suite. Furthermore, allowing zero test files introduces subtle failure modes in watch mode, where the builder cannot monitor for newly created test files.

Because maintaining this safety check is a deliberate design choice, we will not be moving forward with this change. We appreciate your contribution and interest in improving the Angular CLI!

@ant1quar

Copy link
Copy Markdown
Author

Thanks for the detailed explanation, @alan-agius4 — that makes sense. Keeping the fail-fast guard for misconfigured globs and avoiding silent green CI is a tradeoff I hadn't weighed against watch-mode behavior. I'll close out #33055 on my side and look for a bugfix instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants