diff --git a/packages/angular_devkit/build_angular/src/builders/karma/index.ts b/packages/angular_devkit/build_angular/src/builders/karma/index.ts index dd545daf7f22..a4a5d580f43b 100644 --- a/packages/angular_devkit/build_angular/src/builders/karma/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/karma/index.ts @@ -146,6 +146,14 @@ export function execute( logger: context.logger, }; + // Workaround https://github.com/angular/angular-cli/issues/28271, by clearing context by default + // for single run executions. + if (karmaOptions.client?.clearContext === undefined) { + const singleRun = karmaOptions.singleRun ?? false; // Defaults to `false` per Karma docs. + karmaOptions.client ??= {}; + karmaOptions.client.clearContext = singleRun; + } + const parsedKarmaConfig = await karma.config.parseConfig( options.karmaConfig && path.resolve(context.workspaceRoot, options.karmaConfig), transforms.karmaOptions ? transforms.karmaOptions(karmaOptions) : karmaOptions, @@ -208,9 +216,6 @@ function getBuiltInKarmaConfig( 'karma-coverage', '@angular-devkit/build-angular/plugins/karma', ].map((p) => workspaceRootRequire(p)), - client: { - clearContext: false, // leave Jasmine Spec Runner output visible in browser - }, jasmineHtmlReporter: { suppressAll: true, // removes the duplicated traces }, diff --git a/packages/schematics/angular/config/files/karma.conf.js.template b/packages/schematics/angular/config/files/karma.conf.js.template index bac55a495a5b..f8da22b16e55 100644 --- a/packages/schematics/angular/config/files/karma.conf.js.template +++ b/packages/schematics/angular/config/files/karma.conf.js.template @@ -19,7 +19,6 @@ module.exports = function (config) { // for example, you can disable the random execution with `random: false` // or set a specific seed with `seed: 4321` }, - clearContext: false // leave Jasmine Spec Runner output visible in browser }, jasmineHtmlReporter: { suppressAll: true // removes the duplicated traces