From 3140853910e5548fb550e86a055114d027cb91da Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Thu, 29 Aug 2024 11:07:01 -0700 Subject: [PATCH] fix(@angular-devkit/build-angular): clear context in Karma by default for single run executions This works around https://github.com/angular/angular-cli/issues/28271. (cherry picked from commit 3ee21631f481b2e72be2390b5a2cac74824efbb5) --- .../build_angular/src/builders/karma/index.ts | 9 ++++++--- .../angular/config/files/karma.conf.js.template | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) 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 7c96f9fe91e4..b16a8132e722 100644 --- a/packages/angular_devkit/build_angular/src/builders/karma/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/karma/index.ts @@ -99,6 +99,12 @@ export function execute( karmaOptions.singleRun = singleRun; + // Workaround https://github.com/angular/angular-cli/issues/28271, by clearing context by default + // for single run executions. Not clearing context for multi-run (watched) builds allows the + // Jasmine Spec Runner to be visible in the browser after test execution. + karmaOptions.client ??= {}; + karmaOptions.client.clearContext ??= singleRun ?? false; // `singleRun` defaults to `false` per Karma docs. + // Convert browsers from a string to an array if (options.browsers) { karmaOptions.browsers = options.browsers.split(','); @@ -207,9 +213,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