Repository navigation
fix(@angular/build): resolve Vitest artifacts when workspace root is aliased - #34714
Conversation
…aliased In Vitest 5.1.0, `vitestConfig.root` inherits `viteConfig.root`, which resolves symlinks and Windows `subst` drives via `realpathSync`. Normalize paths under `vitestConfig.root` back to `workspaceRoot` in the in-memory provider plugin so internal setup files and build artifacts resolve consistently.
There was a problem hiding this comment.
Code Review
This pull request introduces path normalization to workspace roots in Vitest plugins to handle scenarios where vitestConfig.root differs from workspaceRoot (such as symlinks or subst drives), along with corresponding unit tests. It also updates E2E test configurations to support dynamic sharding, allows bulk package installation in E2E tests, and increases the test timeout from 4 to 8 minutes. Regarding the review feedback, an issue was identified in the path normalization logic where checking relativeToVitestRoot.startsWith('..') could incorrectly match valid files or directories starting with .. (e.g., ..foo/bar.ts). It is recommended to explicitly check if the path is exactly .. or starts with .. followed by a path separator.
5cbb43e to
0813dc5
Compare
84819ed to
e6d76c8
Compare
Starting in Vite 8.3.8 (
vitejs/vite@b643046),windowsLazyRealpathSynccallsfs.realpathSync.nativesynchronously onconfig.root, which resolves Windowssubstdrives and symlinks to their underlying physical path (e.g.,D:/.../test-project) while the Angular CLI'sworkspaceRootretains the logical path (X:\test-project).This caused three issues during Vitest execution on aliased roots:
setupFilesand test files againstvitestConfig.root, which did not matchworkspaceRootor thetestFileToEntryPointmap inangular:test-in-memory-provider.workspaceRootpaths intest.includecausedtinyglobby(running withcwd: vitestConfig.root) to produce cross-drive relative paths (../../../../X:/...) that resolved to invalid paths (D:/X:/...).vitestConfig.rootwhile resolving on-disk spec files underworkspaceRootcaused bare package imports (such as@angular/core/testing) to be loaded twice from both drives.To fix this:
test.includeinVitestExecutor.workspaceRoot,testFileToEntryPoint, andsetupFileSetincreateVitestPlugins(configureVitest) whenvitestConfig.rootdiffers fromworkspaceRoot.