|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { applyVitestBuilder } from '../../utils/vitest'; |
| 3 | +import { ng, silentNpm, exec } from '../../utils/process'; |
| 4 | +import { writeFile } from '../../utils/fs'; |
| 5 | +import { updateJsonFile } from '../../utils/project'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Allow `vitest` import in browser mode. |
| 9 | + * @see https://github.com/angular/angular-cli/issues/31745 |
| 10 | + */ |
| 11 | +export default async function (): Promise<void> { |
| 12 | + await applyVitestBuilder(); |
| 13 | + |
| 14 | + await silentNpm('install', '@vitest/browser-playwright', 'playwright', '--save-dev'); |
| 15 | + await exec('npx', 'playwright', 'install', 'chromium'); |
| 16 | + |
| 17 | + await updateJsonFile('angular.json', (json) => { |
| 18 | + const projects = Object.values(json['projects']); |
| 19 | + const project = projects[0]! as any; |
| 20 | + project['architect']['test']['options']['browsers'] = ['ChromiumHeadless']; |
| 21 | + }); |
| 22 | + |
| 23 | + await writeFile( |
| 24 | + 'src/app/app.spec.ts', |
| 25 | + ` |
| 26 | + import { test, expect } from 'vitest'; |
| 27 | +
|
| 28 | + test('should pass', () => { |
| 29 | + expect(true).toBe(true); |
| 30 | + }); |
| 31 | + `, |
| 32 | + ); |
| 33 | + |
| 34 | + const { stdout } = await ng('test'); |
| 35 | + |
| 36 | + assert.match(stdout, /1 passed/, 'Expected 1 tests to pass.'); |
| 37 | +} |
0 commit comments