Skip to content

Commit fb5e52e

Browse files
committed
fix(@angular/build): adjust sourcemap sources when Vitest wrapper is bypassed
When code coverage is disabled, the Vitest builder bypasses the secondary import wrapper and serves the compiled output directly as the test file. This caused sourcemaps to be incorrect because the `sources` field in the map (relative to the build root) was being resolved relative to the test file's location. This commit adjusts the `sources` in the sourcemap to be relative to the test file's directory, ensuring correct source mapping in debuggers.
1 parent 5469999 commit fb5e52e

File tree

1 file changed

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

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,17 @@ export function createVitestPlugins(pluginOptions: PluginOptions): VitestPlugins
291291
if (map) {
292292
if (!map.sources?.length && !map.sourcesContent?.length && !map.mappings) {
293293
map.sources = ['virtual:builder'];
294+
} else if (!vitestConfig.coverage.enabled && Array.isArray(map.sources)) {
295+
map.sources = (map.sources as string[]).map((source) => {
296+
if (source.startsWith('angular:')) {
297+
return source;
298+
}
299+
300+
// source is relative to the workspace root because the output file is at the root of the output.
301+
const absoluteSource = path.join(workspaceRoot, source);
302+
303+
return toPosixPath(path.relative(path.dirname(id), absoluteSource));
304+
});
294305
}
295306
}
296307

0 commit comments

Comments
 (0)