Skip to content

Commit d82ad5f

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 d82ad5f

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
15+
// Create vitest-base.config.ts
16+
await writeFile(
17+
'vitest-base.config.ts',
18+
`
19+
import { defineConfig } from 'vitest/config';
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(
53+
'test',
54+
'--no-watch',
55+
'--runner-config',
56+
);
57+
58+
assert.match(stdout, /3 passed/, 'Expected 3 tests to pass.');
59+
}

0 commit comments

Comments
 (0)