MCPcopy Index your code
hub / github.com/angular/angular-cli / executeBrowserTest

Function executeBrowserTest

tests/e2e/utils/puppeteer.ts:13–93  ·  view source on GitHub ↗
(options: BrowserTestOptions = {})

Source from the content-addressed store, hash-verified

11}
12
13export async function executeBrowserTest(options: BrowserTestOptions = {}) {
14 let url = options.baseUrl;
15 let hasStartedServer = false;
16
17 try {
18 if (!url) {
19 // Start serving and find address (1 - Webpack; 2 - Vite)
20 const match = /(?:open your browser on|Local:)\s+(http:\/\/localhost:\d+\/)/;
21 const serveArgs = ['serve', '--port=0', '--no-watch', '--no-live-reload'];
22 if (options.project) {
23 serveArgs.push(options.project);
24 }
25 if (options.configuration) {
26 serveArgs.push(`--configuration=${options.configuration}`);
27 }
28
29 const { stdout } = await execAndWaitForOutputToMatch('ng', serveArgs, match, {
30 ...process.env,
31 'NO_COLOR': '1',
32 });
33 url = stripVTControlCharacters(stdout).match(match)?.[1];
34 if (!url) {
35 throw new Error('Could not find serving URL');
36 }
37 hasStartedServer = true;
38 }
39
40 const browser = await launch({
41 executablePath: process.env['CHROME_BIN'],
42 headless: true,
43 args: ['--no-sandbox'],
44 });
45 try {
46 const page = await browser.newPage();
47
48 // Capture errors
49 const errors: string[] = [];
50 page.on('console', (msg) => {
51 if (msg.type() === 'error') {
52 errors.push(msg.text());
53 }
54 });
55 page.on('pageerror', (err) => {
56 const error = `${err}`;
57 if (!error.includes('Hot Module Replacement is disabled')) {
58 errors.push(error);
59 }
60 });
61
62 await page.goto(url);
63
64 if (options.checkFn) {
65 await options.checkFn(page);
66 } else {
67 // Default check: verify h1 content and no browser errors
68 const expectedText = options.expectedTitleText || 'Hello, test-project';
69
70 // Wait for the h1 element to appear and contain the expected text

Calls 8

killAllProcessesFunction · 0.90
onMethod · 0.80
textMethod · 0.80
querySelectorMethod · 0.80
closeMethod · 0.80
pushMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected