Skip to content

Commit 9cb03fe

Browse files
committed
fix(@angular/build): warn about performance of test.exclude in vitest configuration
When a user specifies `test.exclude` inside their `vitest.config.ts`, the tests are correctly excluded during Vitest's execution phase. However, because the Angular CLI extracts test files earlier in the process using its own `exclude` builder option, those skipped tests are still unnecessarily compiled by esbuild in-memory. This adds a warning to explicitly notify developers of this hidden build overhead and suggests using the Angular CLI `exclude` option instead to improve performance.
1 parent 1a8376b commit 9cb03fe

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ export async function createVitestConfigPlugin(
106106
delete testConfig.watch;
107107
}
108108

109+
if (testConfig?.exclude) {
110+
this.warn(
111+
'The "test.exclude" option in the Vitest configuration file is evaluated after ' +
112+
'tests are compiled. For better build performance, please use the Angular CLI ' +
113+
'"exclude" option instead.',
114+
);
115+
}
116+
109117
// Merge user-defined plugins from the Vitest config with the CLI's internal plugins.
110118
if (config.plugins) {
111119
const userPlugins = config.plugins.filter(

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,38 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
348348
// );
349349
});
350350

351+
it('should warn about performance when "test.exclude" option is in runnerConfig file', async () => {
352+
harness.useTarget('test', {
353+
...BASE_OPTIONS,
354+
runnerConfig: 'vitest.config.ts',
355+
});
356+
357+
harness.writeFile(
358+
'vitest.config.ts',
359+
`
360+
import { defineConfig } from 'vitest/config';
361+
export default defineConfig({
362+
test: {
363+
exclude: ['src/app/non-existent.spec.ts'],
364+
},
365+
});
366+
`,
367+
);
368+
369+
const { result, logs } = await harness.executeOnce();
370+
expect(result?.success).toBeTrue();
371+
372+
// TODO: Re-enable once Vite logs are remapped through build system
373+
// expect(logs).toContain(
374+
// jasmine.objectContaining({
375+
// level: 'warn',
376+
// message: jasmine.stringMatching(
377+
// 'The "test.exclude" option in the Vitest configuration file is evaluated after',
378+
// ),
379+
// }),
380+
// );
381+
});
382+
351383
it(`should append "test.setupFiles" (string) from runnerConfig to the CLI's setup`, async () => {
352384
harness.useTarget('test', {
353385
...BASE_OPTIONS,

0 commit comments

Comments
 (0)