diff --git a/tests/legacy-cli/e2e/utils/process.ts b/tests/legacy-cli/e2e/utils/process.ts index 5b7ad3d8dcd5..cbd39cdf2cc1 100644 --- a/tests/legacy-cli/e2e/utils/process.ts +++ b/tests/legacy-cli/e2e/utils/process.ts @@ -77,7 +77,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise((resolve, reject) => { + const processPromise = new Promise((resolve, reject) => { let stdout = ''; let stderr = ''; let matched = false; @@ -158,6 +158,25 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise = new Promise((_resolve, reject) => { + // Wait for 60 seconds and timeout. + const duration = 60_000; + timeout = setTimeout(() => { + reject( + new Error(`Waiting for ${options.waitForMatch} timed out (timeout: ${duration}msec)...`), + ); + }, duration); + }); + + return Promise.race([timeoutPromise, processPromise]).finally( + () => timeout && clearTimeout(timeout), + ); } export function extractNpmEnv() {