( cmd: string, args: string[], match: RegExp, env?: NodeJS.ProcessEnv, )
| 327 | } |
| 328 | |
| 329 | export async function execAndWaitForOutputToMatch( |
| 330 | cmd: string, |
| 331 | args: string[], |
| 332 | match: RegExp, |
| 333 | env?: NodeJS.ProcessEnv, |
| 334 | ) { |
| 335 | if (cmd === 'ng' && args[0] === 'serve') { |
| 336 | // Accept matches up to 20 times after the initial match. |
| 337 | // Useful because the Webpack watcher can rebuild a few times due to files changes that |
| 338 | // happened just before the build (e.g. `git clean`). |
| 339 | // This seems to be due to host file system differences, see |
| 340 | // https://nodejs.org/docs/latest/api/fs.html#fs_caveats |
| 341 | const maxRetries = 20; |
| 342 | let lastResult = await _exec({ waitForMatch: match, env }, cmd, args); |
| 343 | |
| 344 | for (let i = 0; i < maxRetries; i++) { |
| 345 | try { |
| 346 | lastResult = await waitForAnyProcessOutputToMatch(match, 2500); |
| 347 | } catch { |
| 348 | // If we timeout (no new match found), we assume the process is stable. |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | return lastResult; |
| 354 | } else { |
| 355 | return _exec({ waitForMatch: match, env }, cmd, args); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | export function ng(...args: string[]) { |
| 360 | const argv = getGlobalVariable('argv'); |
no test coverage detected