From f1bd6fe2137ce76a5d29c22d7c298d7aaee13352 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Wed, 28 Oct 2026 08:50:24 +0600 Subject: [PATCH 1/3] fix(@angular/build): warn about unsupported options in the unit-test karma runner The karma runner silently ignored `providersFile`, `outputFile` and `coverageReporters`. For example, `ng test --runner karma --coverage --coverage-reporters lcov` wrote no `lcov.info` and printed nothing. Log the same "not supported" warning that the runner already logs for its other unsupported options. --- .../unit-test/runners/karma/executor.ts | 18 ++++++ .../unit-test/runners/karma/executor_spec.ts | 56 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts diff --git a/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts b/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts index 4b06e6f7b81a..279a4b7c47b2 100644 --- a/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts +++ b/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts @@ -53,6 +53,24 @@ export class KarmaExecutor implements TestExecutor { ); } + if (unitTestOptions.providersFile) { + context.logger.warn( + 'The "karma" test runner does not support the "providersFile" option. The option will be ignored.', + ); + } + + if (unitTestOptions.outputFile) { + context.logger.warn( + 'The "karma" test runner does not support the "outputFile" option. The option will be ignored.', + ); + } + + if (unitTestOptions.coverage.reporters) { + context.logger.warn( + 'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.', + ); + } + const buildTargetOptions = (await context.validateOptions( await context.getTargetOptions(unitTestOptions.buildTarget), await context.getBuilderNameForTarget(unitTestOptions.buildTarget), diff --git a/packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts b/packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts new file mode 100644 index 000000000000..6eb06bab7793 --- /dev/null +++ b/packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts @@ -0,0 +1,56 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + +import type { BuilderContext } from '@angular-devkit/architect'; +import type { NormalizedUnitTestBuilderOptions } from '../../options'; +import { KarmaExecutor } from './executor'; + +describe('KarmaExecutor', () => { + async function getWarnings(options: Record): Promise { + const warn = jasmine.createSpy('warn'); + // The unsupported option warnings are logged before the build target is read, so stop there. + const context = { + logger: { warn }, + getTargetOptions: () => Promise.reject(new Error('stop')), + } as unknown as BuilderContext; + + const executor = new KarmaExecutor(context, { + setupFiles: [], + coverage: { enabled: false }, + ...options, + } as unknown as NormalizedUnitTestBuilderOptions); + + await expectAsync(executor.execute()[Symbol.asyncIterator]().next()).toBeRejectedWithError( + 'stop', + ); + + return warn.calls.allArgs().map(([message]) => message); + } + + it('warns that the "providersFile" option is not supported', async () => { + expect(await getWarnings({ providersFile: '/src/test-providers.ts' })).toContain( + 'The "karma" test runner does not support the "providersFile" option. The option will be ignored.', + ); + }); + + it('warns that the "outputFile" option is not supported', async () => { + expect(await getWarnings({ outputFile: 'test-results.xml' })).toContain( + 'The "karma" test runner does not support the "outputFile" option. The option will be ignored.', + ); + }); + + it('warns that the "coverageReporters" option is not supported', async () => { + expect(await getWarnings({ coverage: { enabled: true, reporters: [['lcov', {}]] } })).toContain( + 'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.', + ); + }); + + it('does not warn when no unsupported options are set', async () => { + expect(await getWarnings({})).toEqual([]); + }); +}); From 5ad14ad4d19b93141336dd33189206434bd7b37c Mon Sep 17 00:00:00 2001 From: Shuaib Hasan Akib <48770016+MeAkib@users.noreply.github.com> Date: Wed, 28 Oct 2026 08:53:39 +0600 Subject: [PATCH 2/3] fixup! fix(@angular/build): warn about unsupported options in the unit-test karma runner Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../build/src/builders/unit-test/runners/karma/executor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts b/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts index 279a4b7c47b2..8fa7a5fb3632 100644 --- a/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts +++ b/packages/angular/build/src/builders/unit-test/runners/karma/executor.ts @@ -65,7 +65,7 @@ export class KarmaExecutor implements TestExecutor { ); } - if (unitTestOptions.coverage.reporters) { + if (unitTestOptions.coverage?.reporters) { context.logger.warn( 'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.', ); From 0eac9a5102d8e65e576132ad5445fb6da4b09eb2 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Wed, 28 Oct 2026 14:41:31 +0600 Subject: [PATCH 3/3] fixup! fix(@angular/build): warn about unsupported options in the unit-test karma runner --- .../unit-test/runners/karma/executor_spec.ts | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts diff --git a/packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts b/packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts deleted file mode 100644 index 6eb06bab7793..000000000000 --- a/packages/angular/build/src/builders/unit-test/runners/karma/executor_spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -import type { BuilderContext } from '@angular-devkit/architect'; -import type { NormalizedUnitTestBuilderOptions } from '../../options'; -import { KarmaExecutor } from './executor'; - -describe('KarmaExecutor', () => { - async function getWarnings(options: Record): Promise { - const warn = jasmine.createSpy('warn'); - // The unsupported option warnings are logged before the build target is read, so stop there. - const context = { - logger: { warn }, - getTargetOptions: () => Promise.reject(new Error('stop')), - } as unknown as BuilderContext; - - const executor = new KarmaExecutor(context, { - setupFiles: [], - coverage: { enabled: false }, - ...options, - } as unknown as NormalizedUnitTestBuilderOptions); - - await expectAsync(executor.execute()[Symbol.asyncIterator]().next()).toBeRejectedWithError( - 'stop', - ); - - return warn.calls.allArgs().map(([message]) => message); - } - - it('warns that the "providersFile" option is not supported', async () => { - expect(await getWarnings({ providersFile: '/src/test-providers.ts' })).toContain( - 'The "karma" test runner does not support the "providersFile" option. The option will be ignored.', - ); - }); - - it('warns that the "outputFile" option is not supported', async () => { - expect(await getWarnings({ outputFile: 'test-results.xml' })).toContain( - 'The "karma" test runner does not support the "outputFile" option. The option will be ignored.', - ); - }); - - it('warns that the "coverageReporters" option is not supported', async () => { - expect(await getWarnings({ coverage: { enabled: true, reporters: [['lcov', {}]] } })).toContain( - 'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.', - ); - }); - - it('does not warn when no unsupported options are set', async () => { - expect(await getWarnings({})).toEqual([]); - }); -});