Skip to content

Commit 87f4121

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular/build): exclude only source test files with unit-test vitest support
When using the experimental unit-test builder with the vitest runner and code coverage, the automatic coverage excludes are now adjust to not include the bundled test files. This previously prevent accurate coverage analysis. Vite does this as a convenience but is problematic for the bundling strategy employed by the builder's test setup. To workaround this, the excludes are adjusted here to only automatically exclude the TypeScript source test files.
1 parent db74fb3 commit 87f4121

File tree

1 file changed

+15
-1
lines changed
  • packages/angular/build/src/builders/unit-test

1 file changed

+15
-1
lines changed

packages/angular/build/src/builders/unit-test/builder.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,25 @@ export async function* execute(
230230
reporters: normalizedOptions.reporters ?? ['default'],
231231
coverage: {
232232
enabled: normalizedOptions.codeCoverage,
233-
exclude: normalizedOptions.codeCoverageExclude,
234233
excludeAfterRemap: true,
235234
},
236235
...debugOptions,
237236
},
237+
plugins: [
238+
{
239+
name: 'angular-coverage-exclude',
240+
configureVitest(context) {
241+
// Adjust coverage excludes to not include the otherwise automatically inserted included unit tests.
242+
// Vite does this as a convenience but is problematic for the bundling strategy employed by the
243+
// builder's test setup. To workaround this, the excludes are adjusted here to only automatically
244+
// exclude the TypeScript source test files.
245+
context.project.config.coverage.exclude = [
246+
...(normalizedOptions.codeCoverageExclude ?? []),
247+
'**/*.{test,spec}.?(c|m)ts',
248+
];
249+
},
250+
},
251+
],
238252
});
239253

240254
// Check if all the tests pass to calculate the result

0 commit comments

Comments
 (0)