Skip to content

Commit 7a9dd6b

Browse files
committed
fix(@angular/build): correctly resolve absolute setup file paths in Vitest
The `resolveId` hook in the Vitest runner plugins now correctly handles absolute paths. Previously, the logic would blindly join the base directory with the file ID, which caused issues when the ID was already a fully qualified absolute path within the workspace. The updated logic now checks if the ID is absolute and located within the base directory before deciding whether to join paths, ensuring compatibility with both absolute paths and Vitest's short-form root-relative paths. (cherry picked from commit 8ae7f59)
1 parent 0a8860d commit 7a9dd6b

File tree

1 file changed

+11
-1
lines changed
  • packages/angular/build/src/builders/unit-test/runners/vitest

1 file changed

+11
-1
lines changed

packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,17 @@ export function createVitestPlugins(pluginOptions: PluginOptions): VitestPlugins
233233
}
234234

235235
// Construct the full, absolute path and normalize it to POSIX format.
236-
const fullPath = toPosixPath(path.join(baseDir, id));
236+
let fullPath: string;
237+
if (path.isAbsolute(id)) {
238+
const relativeId = path.relative(baseDir, id);
239+
fullPath =
240+
!relativeId.startsWith('..') && !path.isAbsolute(relativeId)
241+
? id
242+
: path.join(baseDir, id);
243+
} else {
244+
fullPath = path.join(baseDir, id);
245+
}
246+
fullPath = toPosixPath(fullPath);
237247

238248
if (testFileToEntryPoint.has(fullPath)) {
239249
return fullPath;

0 commit comments

Comments
 (0)