Skip to content

fix(@angular/build): correct Vitest builder watch mode execution #30966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

clydin
Copy link
Member

@clydin clydin commented Aug 19, 2025

The experimental Vitest-based unit test builder did not always correctly re-run tests in watch mode.

This commit refactors the Vitest executor to provide more accurate watch mode behavior by:

  • Disabling Vitest's internal file watcher (watch: null) to make the Angular builder's watcher the single source of truth.
  • Triggering a test run via vitest.rerunTestSpecifications() within the execute method after each incremental build is complete.

@clydin clydin added the target: major This PR is targeted for the next major release label Aug 19, 2025
@clydin clydin force-pushed the unit-test/watch-accuracy branch from 3f47f37 to 1672128 Compare August 19, 2025 21:34
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 19, 2025
@clydin clydin force-pushed the unit-test/watch-accuracy branch 3 times, most recently from bc782d3 to e4ba249 Compare August 20, 2025 18:27
clydin added 2 commits August 20, 2025 16:44
The experimental Vitest-based unit test builder did not always correctly re-run tests in watch mode.

This commit refactors the Vitest executor to provide more accurate watch mode behavior by:
- Disabling Vitest's internal file watcher (`watch: null`) to make the Angular builder's watcher the single source of truth.
- Triggering a test run via `vitest.rerunTestSpecifications()` within the `execute` method after each incremental build is complete.
The Vitest-based unit test builder created temporary output directories within `dist/test-out` for each run but did not remove them upon completion. This led to an accumulation of orphaned directories, consuming unnecessary disk space.

This commit introduces robust cleanup logic to the `VitestExecutor` by:
- Deleting the temporary output directory during graceful shutdown using the `asyncDispose` method.
- Registering a `SIGINT` process handler to ensure the directory is also removed during forceful interruptions, such as when a user presses `Ctrl-C` in watch mode.
@clydin clydin force-pushed the unit-test/watch-accuracy branch from e4ba249 to b9c49e3 Compare August 20, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant