Skip to content

Commit

Permalink
Revert "add retry mechanism to the REST API discovery"
Browse files Browse the repository at this point in the history
This reverts commit 393c297.
  • Loading branch information
WunderBart committed Jun 5, 2024
1 parent 4bee3ae commit 6d2b1c3
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions packages/e2e-test-utils-playwright/src/request-utils/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import * as fs from 'fs/promises';
import { dirname } from 'path';
import { expect } from '@playwright/test';
import type { APIRequestContext } from '@playwright/test';

/**
Expand All @@ -23,31 +22,18 @@ function splitRequestsToChunks( requests: BatchRequest[], chunkSize: number ) {
}

async function getAPIRootURL( request: APIRequestContext ) {
let restLink: unknown = null;

// Retry until the REST API root URL is discovered.
// See https://github.com/WordPress/gutenberg/issues/61627
await expect
.poll(
async () => {
// Discover the API root url using link header.
// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header
const response = await request.head( WP_BASE_URL );
const links = response.headers().link;
restLink = links?.match(
/<([^>]+)>; rel="https:\/\/api\.w\.org\/"/
);

return restLink;
},
{
message: 'Failed to discover REST API endpoint.',
timeout: 60_000, // 1 minute.
}
)
.not.toBeFalsy();

const [ , rootURL ] = restLink as RegExpMatchArray;
// Discover the API root url using link header.
// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header
const response = await request.head( WP_BASE_URL );
const links = response.headers().link;
const restLink = links?.match( /<([^>]+)>; rel="https:\/\/api\.w\.org\/"/ );

if ( ! restLink ) {
throw new Error( `Failed to discover REST API endpoint.
Link header: ${ links }` );
}

const [ , rootURL ] = restLink;

return rootURL;
}
Expand Down

0 comments on commit 6d2b1c3

Please sign in to comment.