Skip to content

Commit 0f1ee90

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.
1 parent 4560604 commit 0f1ee90

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
@@ -229,7 +229,17 @@ export function createVitestPlugins(pluginOptions: PluginOptions): VitestPlugins
229229
}
230230

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

234244
if (testFileToEntryPoint.has(fullPath)) {
235245
return fullPath;

0 commit comments

Comments
 (0)