From 7f4f35b126ec0dc1e275223b00317db5cc1d7ced Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 29 Jul 2023 21:32:53 +0200 Subject: [PATCH] test: improve waitForStdout stacktrace --- test/test-utils/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/test-utils/index.ts b/test/test-utils/index.ts index 171a245cd..c3016704d 100644 --- a/test/test-utils/index.ts +++ b/test/test-utils/index.ts @@ -111,12 +111,15 @@ export async function runCli(command: string, _options?: Options | string, ...ar subprocess.stdin!.write(text) }, waitForStdout(expected: string) { + const error = new Error('Timeout error') + Error.captureStackTrace(error, this.waitForStdout) return new Promise((resolve, reject) => { if (this.stdout.includes(expected)) return resolve() const timeout = setTimeout(() => { - reject(new Error(`Timeout when waiting for output "${expected}".\nReceived:\n${this.stdout} \nStderr:\n${this.stderr}`)) + error.message = `Timeout when waiting for output "${expected}".\nReceived:\n${this.stdout} \nStderr:\n${this.stderr}` + reject(error) }, process.env.CI ? 20_000 : 4_000) const listener = () => { @@ -132,12 +135,15 @@ export async function runCli(command: string, _options?: Options | string, ...ar }) }, waitForStderr(expected: string) { + const error = new Error('Timeout') + Error.captureStackTrace(error, this.waitForStderr) return new Promise((resolve, reject) => { if (this.stderr.includes(expected)) return resolve() const timeout = setTimeout(() => { - reject(new Error(`Timeout when waiting for error "${expected}".\nReceived:\n${this.stderr}\nStdout:\n${this.stdout}`)) + error.message = `Timeout when waiting for error "${expected}".\nReceived:\n${this.stderr}\nStdout:\n${this.stdout}` + reject(error) }, process.env.CI ? 20_000 : 4_000) const listener = () => { -- 2.51.2