MCPcopy Index your code
hub / github.com/angular/angular-cli / applyVitestBuilder

Function applyVitestBuilder

tests/e2e/utils/vitest.ts:5–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4/** Updates the `test` builder in the current workspace to use Vitest. */
5export async function applyVitestBuilder(): Promise<void> {
6 // These deps matches the deps in `@schematics/angular`
7 await installPackage('vitest@^4.0.8');
8 await installPackage('jsdom@^27.1.0');
9
10 await updateJsonFile('angular.json', (json) => {
11 const projects = Object.values(json['projects']);
12 if (projects.length !== 1) {
13 throw new Error(
14 `Expected exactly one project but found ${projects.length} projects named ${Object.keys(
15 json['projects'],
16 ).join(', ')}`,
17 );
18 }
19 const project = projects[0]! as any;
20
21 // Update to Vitest builder.
22 const test = project['architect']['test'];
23 test['builder'] = '@angular/build:unit-test';
24 test['options'] = {};
25 });
26
27 await updateJsonFile('tsconfig.spec.json', (tsconfig) => {
28 tsconfig['compilerOptions']['types'] = ['vitest/globals'];
29 });
30}

Calls 4

installPackageFunction · 0.90
updateJsonFileFunction · 0.90
valuesMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected