MCPcopy Create free account
hub / github.com/SoCreate/angular-playground / waitForNgServe

Function waitForNgServe

projects/cli/src/utils.ts:16–42  ·  view source on GitHub ↗
(browser: Browser, hostUrl: string, timeoutAttempts: number)

Source from the content-addressed store, hash-verified

14 * of retries before it finally fails.
15 */
16export async function waitForNgServe(browser: Browser, hostUrl: string, timeoutAttempts: number) {
17 if (timeoutAttempts === 0) {
18 await browser.close();
19 throw new Error('Unable to connect to Playground.');
20 }
21
22 const page = await browser.newPage();
23 let ngServeErrors = 0;
24
25 try {
26 page.on('console', (msg: ConsoleMessage) => {
27 if (msg.type() === 'error') {
28 ngServeErrors++;
29 }
30 });
31 await page.goto(hostUrl);
32 setTimeout(() => page.close()); // close page to prevent memory leak
33 } catch (e) {
34 await page.close();
35 await delay(1000);
36 await waitForNgServe(browser, hostUrl, timeoutAttempts - 1);
37 }
38
39 if (ngServeErrors > 0) {
40 throw new Error('ng serve failure');
41 }
42}

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 1

delayFunction · 0.85

Tested by

no test coverage detected