Skip to content

Commit f1bd6fe

Browse files
committed
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.
1 parent 19de4c3 commit f1bd6fe

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

‎packages/angular/build/src/builders/unit-test/runners/karma/executor.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ export class KarmaExecutor implements TestExecutor {
5353
);
5454
}
5555

56+
if (unitTestOptions.providersFile) {
57+
context.logger.warn(
58+
'The "karma" test runner does not support the "providersFile" option. The option will be ignored.',
59+
);
60+
}
61+
62+
if (unitTestOptions.outputFile) {
63+
context.logger.warn(
64+
'The "karma" test runner does not support the "outputFile" option. The option will be ignored.',
65+
);
66+
}
67+
68+
if (unitTestOptions.coverage.reporters) {
69+
context.logger.warn(
70+
'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.',
71+
);
72+
}
73+
5674
const buildTargetOptions = (await context.validateOptions(
5775
await context.getTargetOptions(unitTestOptions.buildTarget),
5876
await context.getBuilderNameForTarget(unitTestOptions.buildTarget),
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import type { BuilderContext } from '@angular-devkit/architect';
10+
import type { NormalizedUnitTestBuilderOptions } from '../../options';
11+
import { KarmaExecutor } from './executor';
12+
13+
describe('KarmaExecutor', () => {
14+
async function getWarnings(options: Record<string, unknown>): Promise<string[]> {
15+
const warn = jasmine.createSpy('warn');
16+
// The unsupported option warnings are logged before the build target is read, so stop there.
17+
const context = {
18+
logger: { warn },
19+
getTargetOptions: () => Promise.reject(new Error('stop')),
20+
} as unknown as BuilderContext;
21+
22+
const executor = new KarmaExecutor(context, {
23+
setupFiles: [],
24+
coverage: { enabled: false },
25+
...options,
26+
} as unknown as NormalizedUnitTestBuilderOptions);
27+
28+
await expectAsync(executor.execute()[Symbol.asyncIterator]().next()).toBeRejectedWithError(
29+
'stop',
30+
);
31+
32+
return warn.calls.allArgs().map(([message]) => message);
33+
}
34+
35+
it('warns that the "providersFile" option is not supported', async () => {
36+
expect(await getWarnings({ providersFile: '/src/test-providers.ts' })).toContain(
37+
'The "karma" test runner does not support the "providersFile" option. The option will be ignored.',
38+
);
39+
});
40+
41+
it('warns that the "outputFile" option is not supported', async () => {
42+
expect(await getWarnings({ outputFile: 'test-results.xml' })).toContain(
43+
'The "karma" test runner does not support the "outputFile" option. The option will be ignored.',
44+
);
45+
});
46+
47+
it('warns that the "coverageReporters" option is not supported', async () => {
48+
expect(await getWarnings({ coverage: { enabled: true, reporters: [['lcov', {}]] } })).toContain(
49+
'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.',
50+
);
51+
});
52+
53+
it('does not warn when no unsupported options are set', async () => {
54+
expect(await getWarnings({})).toEqual([]);
55+
});
56+
});

0 commit comments

Comments
 (0)