()
| 3 | |
| 4 | /** Updates the `test` builder in the current workspace to use Vitest. */ |
| 5 | export 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 | } |
no test coverage detected