Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/angular/build/src/builders/karma/application_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,35 @@ async function initializeApplication(
parsedKarmaConfig.reporters ??= [];
parsedKarmaConfig.reporters.push(AngularPolyfillsPlugin.NAME);

// Adjust karma junit reporter outDir location to maintain previous (devkit) behavior
// The base path for the reporter was previously the workspace root.
// To keep the files in the same location, the reporter's output directory is adjusted
// to be relative to the workspace root when using junit.
if (parsedKarmaConfig.reporters?.some((reporter) => reporter === 'junit')) {
if ('junitReporter' in parsedKarmaConfig) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const junitReporterOptions = (parsedKarmaConfig as any)['junitReporter'] as {
outputDir?: unknown;
};
if (junitReporterOptions.outputDir == undefined) {
junitReporterOptions.outputDir = context.workspaceRoot;
} else if (
typeof junitReporterOptions.outputDir === 'string' &&
!path.isAbsolute(junitReporterOptions.outputDir)
) {
junitReporterOptions.outputDir = path.join(
context.workspaceRoot,
junitReporterOptions.outputDir,
);
}
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(parsedKarmaConfig as any)['junitReporter'] = {
outputDir: context.workspaceRoot,
};
}
}

// When using code-coverage, auto-add karma-coverage.
// This was done as part of the karma plugin for webpack.
if (
Expand Down
27 changes: 27 additions & 0 deletions tests/legacy-cli/e2e/tests/test/karma-junit-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expectFileMatchToExist, replaceInFile } from '../../utils/fs';
import { installPackage } from '../../utils/packages';
import { silentNg } from '../../utils/process';

const E2E_CUSTOM_LAUNCHER = `
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage'],
},
},
restartOnFileChange: true,
`;

export default async function () {
await installPackage('karma-junit-reporter');
await silentNg('generate', 'config', 'karma');

await replaceInFile('karma.conf.js', 'karma-jasmine-html-reporter', 'karma-junit-reporter');
await replaceInFile('karma.conf.js', `'kjhtml'`, `'junit'`);

await replaceInFile('karma.conf.js', `restartOnFileChange: true`, E2E_CUSTOM_LAUNCHER);

await silentNg('test', '--no-watch');

await expectFileMatchToExist('.', /TESTS\-.+\.xml/);
}