Skip to content

Commit

Permalink
E2E Utils: Add retry mechanism to the REST API discovery (WordPress#6…
Browse files Browse the repository at this point in the history
…2331)

Co-authored-by: WunderBart <bartkalisz@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: GraemeF <graemef@git.wordpress.org>
  • Loading branch information
6 people authored and patil-vipul committed Jun 17, 2024
1 parent 0df5a4b commit 1cbb84b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 27 additions & 4 deletions packages/e2e-test-utils-playwright/src/request-utils/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 1 addition & 3 deletions test/performance/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1cbb84b

Please sign in to comment.