Skip to content

Commit 1cbb84b

Browse files
WunderBartkevin940726swissspidyMamadukaGraemeF
authored andcommitted
E2E Utils: Add retry mechanism to the REST API discovery (WordPress#62331)
Co-authored-by: WunderBart <[email protected]> Co-authored-by: kevin940726 <[email protected]> Co-authored-by: swissspidy <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: GraemeF <[email protected]>
1 parent 0df5a4b commit 1cbb84b

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/e2e-test-utils-playwright/src/request-utils/rest.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import * as fs from 'fs/promises';
55
import { dirname } from 'path';
6+
import { expect } from '@playwright/test';
67
import type { APIRequestContext } from '@playwright/test';
78

89
/**
@@ -39,10 +40,32 @@ async function getAPIRootURL( request: APIRequestContext ) {
3940
}
4041

4142
async function setupRest( this: RequestUtils ): Promise< StorageState > {
42-
const [ nonce, rootURL ] = await Promise.all( [
43-
this.login(),
44-
getAPIRootURL( this.request ),
45-
] );
43+
let nonce = '';
44+
let rootURL = '';
45+
46+
// Poll until the REST API is discovered.
47+
// See https://github.com/WordPress/gutenberg/issues/61627
48+
await expect
49+
.poll(
50+
async () => {
51+
try {
52+
[ nonce, rootURL ] = await Promise.all( [
53+
this.login(),
54+
getAPIRootURL( this.request ),
55+
] );
56+
} catch ( error ) {
57+
// Prints the error if the timeout is reached.
58+
return error;
59+
}
60+
61+
return nonce && rootURL ? true : false;
62+
},
63+
{
64+
message: 'Failed to setup REST API.',
65+
timeout: 60_000, // 1 minute.
66+
}
67+
)
68+
.toBe( true );
4669

4770
const { cookies } = await this.request.storageState();
4871

test/performance/playwright.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ process.env.ASSETS_PATH = path.join( __dirname, 'assets' );
1414

1515
const config = defineConfig( {
1616
...baseConfig,
17-
reporter: process.env.CI
18-
? './config/performance-reporter.ts'
19-
: [ [ 'list' ], [ './config/performance-reporter.ts' ] ],
17+
reporter: [ [ 'list' ], [ './config/performance-reporter.ts' ] ],
2018
forbidOnly: !! process.env.CI,
2119
fullyParallel: false,
2220
retries: 0,

0 commit comments

Comments
 (0)