Skip to content

Commit 534e4c7

Browse files
committed
test(@angular/build): add E2E test for Vitest custom browser configuration
Add an E2E test to verify that the Vitest runner respects the browser configuration defined in `vitest-base.config.ts` when no CLI overrides are present. This ensures that custom configurations, such as specific browser providers or endpoints, are preserved when users rely solely on the configuration file.
1 parent a5e1e48 commit 534e4c7

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)