Skip to content

Commit 7877d9a

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular/build): ensure disabled vitest config loading
With the experimental `unit-test` builder with the `vitest` runner, the underlying vitest execution will no longer attempt to load external configuration files. The current internal vitest usage does not support integration of external configuration files. (cherry picked from commit 25c80b3)
1 parent a42e045 commit 7877d9a

File tree

1 file changed

+38
-30
lines changed
  • packages/angular/build/src/builders/unit-test

1 file changed

+38
-30
lines changed

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

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -217,39 +217,47 @@ export async function* execute(
217217

218218
await writeTestFiles(result.files, outputPath);
219219

220-
instance ??= await startVitest('test', undefined /* cliFilters */, undefined /* options */, {
221-
test: {
222-
root: outputPath,
223-
globals: true,
224-
setupFiles,
225-
// Use `jsdom` if no browsers are explicitly configured.
226-
// `node` is effectively no "environment" and the default.
227-
environment: browser ? 'node' : 'jsdom',
228-
watch: normalizedOptions.watch,
229-
browser,
230-
reporters: normalizedOptions.reporters ?? ['default'],
231-
coverage: {
232-
enabled: normalizedOptions.codeCoverage,
233-
excludeAfterRemap: true,
234-
},
235-
...debugOptions,
220+
instance ??= await startVitest(
221+
'test',
222+
undefined /* cliFilters */,
223+
{
224+
// Disable configuration file resolution/loading
225+
config: false,
236226
},
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-
];
227+
{
228+
test: {
229+
root: outputPath,
230+
globals: true,
231+
setupFiles,
232+
// Use `jsdom` if no browsers are explicitly configured.
233+
// `node` is effectively no "environment" and the default.
234+
environment: browser ? 'node' : 'jsdom',
235+
watch: normalizedOptions.watch,
236+
browser,
237+
reporters: normalizedOptions.reporters ?? ['default'],
238+
coverage: {
239+
enabled: normalizedOptions.codeCoverage,
240+
excludeAfterRemap: true,
249241
},
242+
...debugOptions,
250243
},
251-
],
252-
});
244+
plugins: [
245+
{
246+
name: 'angular-coverage-exclude',
247+
configureVitest(context) {
248+
// Adjust coverage excludes to not include the otherwise automatically inserted included unit tests.
249+
// Vite does this as a convenience but is problematic for the bundling strategy employed by the
250+
// builder's test setup. To workaround this, the excludes are adjusted here to only automatically
251+
// exclude the TypeScript source test files.
252+
context.project.config.coverage.exclude = [
253+
...(normalizedOptions.codeCoverageExclude ?? []),
254+
'**/*.{test,spec}.?(c|m)ts',
255+
];
256+
},
257+
},
258+
],
259+
},
260+
);
253261

254262
// Check if all the tests pass to calculate the result
255263
const testModules = instance.state.getTestModules();

0 commit comments

Comments
 (0)