Skip to content

Commit 2c33175

Browse files
committed
fix(@angular/build): resolve junit karma reporter output to workspace root
To maintain behavior with the Webpack-based karma unit-testing available via `@angular-devkit/build-angular`, the application build system based karma testing will now resolve the output directory location of the junit karma reporter to the same workspace root location. This is only performed if the `junit` reporter is enabled and the reporter's `outputDir` option is not an absolute path.
1 parent 01c9d69 commit 2c33175

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

packages/angular/build/src/builders/karma/application_builder.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,35 @@ async function initializeApplication(
577577
parsedKarmaConfig.reporters ??= [];
578578
parsedKarmaConfig.reporters.push(AngularPolyfillsPlugin.NAME);
579579

580+
// Adjust karma junit reporter outDir location to maintain previous (devkit) behavior
581+
// The base path for the reporter was previously the workspace root.
582+
// To keep the files in the same location, the reporter's output directory is adjusted
583+
// to be relative to the workspace root when using junit.
584+
if (parsedKarmaConfig.reporters?.some((reporter) => reporter === 'junit')) {
585+
if ('junitReporter' in parsedKarmaConfig) {
586+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
587+
const junitReporterOptions = (parsedKarmaConfig as any)['junitReporter'] as {
588+
outputDir?: unknown;
589+
};
590+
if (junitReporterOptions.outputDir == undefined) {
591+
junitReporterOptions.outputDir = context.workspaceRoot;
592+
} else if (
593+
typeof junitReporterOptions.outputDir === 'string' &&
594+
!path.isAbsolute(junitReporterOptions.outputDir)
595+
) {
596+
junitReporterOptions.outputDir = path.join(
597+
context.workspaceRoot,
598+
junitReporterOptions.outputDir,
599+
);
600+
}
601+
} else {
602+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
603+
(parsedKarmaConfig as any)['junitReporter'] = {
604+
outputDir: context.workspaceRoot,
605+
};
606+
}
607+
}
608+
580609
// When using code-coverage, auto-add karma-coverage.
581610
// This was done as part of the karma plugin for webpack.
582611
if (

0 commit comments

Comments
 (0)