diff --git a/test/e2e/app-dir/actions/app-action.test.ts b/test/e2e/app-dir/actions/app-action.test.ts index e557955fe0a87f..011bee4e772026 100644 --- a/test/e2e/app-dir/actions/app-action.test.ts +++ b/test/e2e/app-dir/actions/app-action.test.ts @@ -2,7 +2,6 @@ import { FileRef, nextTestSetup } from 'e2e-utils' import { assertHasRedbox, retry, - check, waitFor, getRedboxSource, getDistDir, @@ -527,8 +526,14 @@ describe('app-dir action handling', () => { // navigate to server await browser.elementByCss('#navigate-server').click() - // intentionally bailing after 2 retries so we don't retry to the point where the async function resolves - await check(() => browser.url(), `${next.url}/server`, true, 2) + // intentionally bailing after 2s so we don't retry to the point where the async function resolves + await retry( + async () => { + expect(await browser.url()).toEqual(`${next.url}/server`) + }, + 2000, + 1000 + ) browser = await next.browser('/server') @@ -536,8 +541,14 @@ describe('app-dir action handling', () => { // navigate to client await browser.elementByCss('#navigate-client').click() - // intentionally bailing after 2 retries so we don't retry to the point where the async function resolves - await check(() => browser.url(), `${next.url}/client`, true, 2) + // intentionally bailing after 2s so we don't retry to the point where the async function resolves + await retry( + async () => { + expect(await browser.url()).toEqual(`${next.url}/client`) + }, + 2000, + 1000 + ) }) it('should not block router.back() while a server action is in flight', async () => { @@ -549,8 +560,14 @@ describe('app-dir action handling', () => { await browser.back() - // intentionally bailing after 2 retries so we don't retry to the point where the async function resolves - await check(() => browser.url(), `${next.url}/`, true, 2) + // intentionally bailing after 2s so we don't retry to the point where the async function resolves + await retry( + async () => { + expect(await browser.url()).toEqual(`${next.url}/`) + }, + 2000, + 1000 + ) }) it('should trigger a refresh for a server action that also dispatches a navigation event', async () => { diff --git a/test/e2e/getserversideprops/test/index.test.ts b/test/e2e/getserversideprops/test/index.test.ts index 9f9593d8480675..ea7bc6fb6cc736 100644 --- a/test/e2e/getserversideprops/test/index.test.ts +++ b/test/e2e/getserversideprops/test/index.test.ts @@ -598,13 +598,9 @@ const runTests = (isDev = false, isDeploy = false) => { it('should load a fast refresh page', async () => { const browser = await webdriver(next.url, '/refresh') - expect( - await check( - () => browser.elementByCss('p').text(), - /client loaded/, - false - ) - ).toBe(true) + await retry(async () => { + expect(await browser.elementByCss('p').text()).toMatch(/client loaded/) + }) }) it('should provide correct query value for dynamic page', async () => { diff --git a/test/lib/next-test-utils.ts b/test/lib/next-test-utils.ts index 60faf0f8228c5f..0bdf1fc7836876 100644 --- a/test/lib/next-test-utils.ts +++ b/test/lib/next-test-utils.ts @@ -697,25 +697,18 @@ export async function startCleanStaticServer(dir: string) { /** * Check for content in 1 second intervals timing out after 30 seconds. * @deprecated use retry + expect instead - * @param {() => Promise | unknown} contentFn - * @param {RegExp | string | number} regex - * @param {boolean} hardError - * @param {number} maxRetries - * @returns {Promise} */ export async function check( - contentFn: () => any | Promise, - regex: any, - hardError = true, - maxRetries = 30 -) { - let content - let lastErr + contentFn: () => unknown | Promise, + regex: any +): Promise { + let content: unknown + let lastErr: unknown - for (let tries = 0; tries < maxRetries; tries++) { + for (let tries = 0; tries < 30; tries++) { try { content = await contentFn() - if (typeof regex !== typeof /regex/) { + if (typeof regex !== 'object') { if (regex === content) { return true } @@ -730,11 +723,7 @@ export async function check( } } console.error('TIMED OUT CHECK: ', { regex, content, lastErr }) - - if (hardError) { - throw new Error('TIMED OUT: ' + regex + '\n\n' + content + '\n\n' + lastErr) - } - return false + throw new Error('TIMED OUT: ' + regex + '\n\n' + content + '\n\n' + lastErr) } export class File {