Skip to content

Commit 956ccaa

Browse files
committed
fix(@angular/build): remove default for unit-test coverage option
Removing the default value of `false` for the `coverage` schema option in the unit-test builder. When a default was present, it forced the coverage check in the Vitest plugins to override any user-provided `coverage: { enabled: true }` values set within a custom `vitest.config.ts`. Removing the default explicitly allows the option to be `undefined`, respecting the fallback behavior of the runner configuration. The description was also updated to explicitly document how the Vitest runner resolves the coverage configuration when the builder flag is omitted. (cherry picked from commit 1a8376b)
1 parent 6ec36f5 commit 956ccaa

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/angular/build/src/builders/unit-test/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
},
7676
"coverage": {
7777
"type": "boolean",
78-
"description": "Enables coverage reporting for tests.",
79-
"default": false
78+
"description": "Enables coverage reporting for tests. If not specified, the coverage configuration from a runner configuration file will be used if present. Otherwise, coverage is disabled by default."
8079
},
8180
"coverageInclude": {
8281
"type": "array",

packages/angular/build/src/builders/unit-test/tests/behavior/runner-config-vitest_spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
9292
harness.expectFile('coverage/test/coverage-final.json').toExist();
9393
});
9494

95+
it('should enable coverage when set in runnerConfig file without builder option', async () => {
96+
harness.useTarget('test', {
97+
...BASE_OPTIONS,
98+
runnerConfig: 'vitest.config.ts',
99+
});
100+
101+
harness.writeFile(
102+
'vitest.config.ts',
103+
`
104+
import { defineConfig } from 'vitest/config';
105+
export default defineConfig({
106+
test: {
107+
coverage: {
108+
enabled: true,
109+
},
110+
},
111+
});
112+
`,
113+
);
114+
115+
const { result } = await harness.executeOnce();
116+
expect(result?.success).toBeTrue();
117+
harness.expectFile('coverage/test/coverage-final.json').toExist();
118+
});
119+
95120
it('should exclude test files based on runnerConfig file', async () => {
96121
harness.useTarget('test', {
97122
...BASE_OPTIONS,

0 commit comments

Comments
 (0)