Skip to content

Commit 19b1123

Browse files
committed
fix(@angular/build): allow 'vitest' import in browser mode
This fixes the following error: 'The entry point "vitest" cannot be marked as external' by excluding vitest from the discovered dependencies handed to optimizeDeps.include Closes #31745
1 parent 1ef24a7 commit 19b1123

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

Comments
 (0)