Skip to content

Commit 95c1452

Browse files
committed
test: add e2e test for Vitest browser configuration with Vitest v4
This commits adds a test to validate vitest version 4.
1 parent b36c3f7 commit 95c1452

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import assert from 'node:assert/strict';
2+
import { applyVitestBuilder } from '../../utils/vitest';
3+
import { ng } from '../../utils/process';
4+
import { writeFile } from '../../utils/fs';
5+
import { installPackage } from '../../utils/packages';
6+
7+
export default async function (): Promise<void> {
8+
await applyVitestBuilder();
9+
await installPackage('vitest@4');
10+
await installPackage('playwright@1');
11+
await installPackage('@vitest/browser-playwright@4');
12+
13+
await ng('generate', 'component', 'my-comp');
14+
15+
// Create vitest-base.config.mts
16+
await writeFile(
17+
'vitest-base.config.mts',
18+
`
19+
import { defineConfig } from 'vitest/config';
20+
import { playwright } from '@vitest/browser-playwright';
21+
22+
export default defineConfig({
23+
test: {
24+
browser: {
25+
enabled: true,
26+
provider: playwright({launchOptions: {executablePath: process.env['CHROME_BIN']}}),
27+
instances: [
28+
{ browser: 'chromium' },
29+
],
30+
headless: true,
31+
},
32+
},
33+
});
34+
`,
35+
);
36+
37+
// Create a spec file that asserts browser environment
38+
await writeFile(
39+
'src/browser.spec.ts',
40+
`
41+
describe('Browser Environment Check', () => {
42+
it('should be running in Chromium', () => {
43+
const ua = navigator.userAgent;
44+
// Fail the test if it's not Chrome/Chromium
45+
if (!ua.includes('Chrome') && !ua.includes('Chromium')) {
46+
throw new Error('Expected to be running in Chrome/Chromium, but User Agent is: ' + ua);
47+
}
48+
});
49+
});
50+
`,
51+
);
52+
53+
const { stdout } = await ng('test', '--no-watch', '--runner-config');
54+
55+
assert.match(stdout, /3 passed/, 'Expected 3 tests to pass.');
56+
}

0 commit comments

Comments
 (0)