diff --git a/packages/e2e-test-utils-playwright/src/request-utils/rest.ts b/packages/e2e-test-utils-playwright/src/request-utils/rest.ts index 667ccc1d9294d..79b49dc3c7b64 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/rest.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/rest.ts @@ -3,6 +3,7 @@ */ import * as fs from 'fs/promises'; import { dirname } from 'path'; +import { expect } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; /** @@ -39,10 +40,32 @@ async function getAPIRootURL( request: APIRequestContext ) { } async function setupRest( this: RequestUtils ): Promise< StorageState > { - const [ nonce, rootURL ] = await Promise.all( [ - this.login(), - getAPIRootURL( this.request ), - ] ); + let nonce = ''; + let rootURL = ''; + + // Poll until the REST API is discovered. + // See https://github.com/WordPress/gutenberg/issues/61627 + await expect + .poll( + async () => { + try { + [ nonce, rootURL ] = await Promise.all( [ + this.login(), + getAPIRootURL( this.request ), + ] ); + } catch ( error ) { + // Prints the error if the timeout is reached. + return error; + } + + return nonce && rootURL ? true : false; + }, + { + message: 'Failed to setup REST API.', + timeout: 60_000, // 1 minute. + } + ) + .toBe( true ); const { cookies } = await this.request.storageState(); diff --git a/test/performance/playwright.config.ts b/test/performance/playwright.config.ts index ed221b1dc7bfb..fafca3a589122 100644 --- a/test/performance/playwright.config.ts +++ b/test/performance/playwright.config.ts @@ -14,9 +14,7 @@ process.env.ASSETS_PATH = path.join( __dirname, 'assets' ); const config = defineConfig( { ...baseConfig, - reporter: process.env.CI - ? './config/performance-reporter.ts' - : [ [ 'list' ], [ './config/performance-reporter.ts' ] ], + reporter: [ [ 'list' ], [ './config/performance-reporter.ts' ] ], forbidOnly: !! process.env.CI, fullyParallel: false, retries: 0,