Skip to content

fix(@angular/build): rebase Vitest incremental paths when workspace root is aliased - #34718

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix/vitest-aliased-root-followups
Open

clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix/vitest-aliased-root-followups

Conversation

@clydin

@clydin clydin commented Nov 13, 2026

Copy link
Copy Markdown
Member

When vitestConfig.root differs from workspaceRoot (such as with symlinks or Windows subst drives), VitestExecutor still invalidated and queried test specifications during incremental watch-mode rebuilds using the un-rebased workspaceRoot paths. Because Vitest keys its module graph and test specifications against vitest.config.root, incremental re-runs could fail to invalidate cached modules or locate the affected test specifications.

To address this, extract a rebasePath helper in plugins.ts that converts paths between roots while leaving paths that cannot be expressed relative to the original root (such as files on a different Windows drive) unchanged instead of concatenating them. VitestExecutor now uses this helper during incremental rebuilds to rebase modified output and source file paths onto vitest.config.root when the root is aliased. Additionally, configureVitest now rebases from the original plugin options rather than mutating from the previous root so repeated invocations remain idempotent. plugins_spec.ts is expanded to cover rebasePath, angular: virtual entries, absolute setup files under coverage, and repeated configureVitest calls, and a new executor_spec.ts covers the incremental rebuild paths.

…oot is aliased

When `vitestConfig.root` differs from `workspaceRoot` (such as with symlinks or Windows `subst` drives), `VitestExecutor` still invalidated and queried test specifications during incremental watch-mode rebuilds using the un-rebased `workspaceRoot` paths. Because Vitest keys its module graph and test specifications against `vitest.config.root`, incremental re-runs could fail to invalidate cached modules or locate the affected test specifications.

To address this, extract a `rebasePath` helper in `plugins.ts` that converts paths between roots while leaving paths that cannot be expressed relative to the original root (such as files on a different Windows drive) unchanged instead of concatenating them. `VitestExecutor` now uses this helper during incremental rebuilds to rebase modified output and source file paths onto `vitest.config.root` when the root is aliased. Additionally, `configureVitest` now rebases from the original plugin options rather than mutating from the previous root so repeated invocations remain idempotent. `plugins_spec.ts` is expanded to cover `rebasePath`, `angular:` virtual entries, absolute setup files under coverage, and repeated `configureVitest` calls, and a new `executor_spec.ts` covers the incremental rebuild paths.
@clydin
clydin force-pushed the fix/vitest-aliased-root-followups branch from e7c8b46 to 4d3926d Compare November 13, 2026 21:34
@clydin
clydin marked this pull request as ready for review November 13, 2026 21:42
@clydin clydin added target: rc This PR is targeted for the next release-candidate action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 13, 2026

@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 introduces path rebasing support for the Vitest unit test runner when the Vitest root is aliased (different from the workspace root). It adds a rebasePath utility to correctly map file paths between the workspace root and the Vitest root, ensuring that incremental rebuilds, file invalidations, and setup file loading work correctly in aliased environments. Unit tests have been added to verify these changes. There are no review comments, so I have no feedback to provide.

@clydin
clydin requested a review from alan-agius4 November 13, 2026 21:47
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: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant