diff --git a/tests/internal-tests/src/__tests__/lib/lib.ts b/tests/internal-tests/src/__tests__/lib/lib.ts index 8baf41fe..6156e5bf 100644 --- a/tests/internal-tests/src/__tests__/lib/lib.ts +++ b/tests/internal-tests/src/__tests__/lib/lib.ts @@ -7,6 +7,8 @@ export function waitTime(ms: number): Promise { * Useful in unit-tests as a way to wait until a predicate is fulfilled. */ export async function waitUntil(expectFcn: () => void, maxWaitTime: number): Promise { + const previousErrors: string[] = [] + const startTime = Date.now() while (true) { await waitTime(100) @@ -14,8 +16,22 @@ export async function waitUntil(expectFcn: () => void, maxWaitTime: number): Pro expectFcn() return } catch (err) { + const errorStr = `${err}` + if (previousErrors.length) { + const previousError = previousErrors[previousErrors.length - 1] + if (errorStr !== previousError) { + previousErrors.push(errorStr) + } + } else { + previousErrors.push(errorStr) + } + let waitedTime = Date.now() - startTime - if (waitedTime > maxWaitTime) throw err + if (waitedTime > maxWaitTime) { + console.log(`Previous errors: \n${previousErrors.join('\n')}`) + + throw err + } // else ignore error and try again later } }