Skip to content

Playwright e2e tests are configured to start wp-env but don't wait for REST API to be advertised #61627

@GraemeF

Description

@GraemeF

Description

Playwright is configured to start wp-env if not already running, but when it does the REST API likely isn't ready in time for the globalSetup function to use it. To get around that, the GitHub workflow starts wp-env ahead of the tests in the hope that it's started by the time the globalSetup function tries to use it.

Step-by-step reproduction instructions

In the gutenberg repo, make sure wp-env is not already running, then run the e2e tests:

npm run test:e2e

Expected behaviour

Playwright should wait for all required services to be available before running tests, or should not be configured to start wp-env at all, to clarify that this needs to be done ahead of time.

Actual behaviour

Playwright starts wp-env, waits for the WordPress port to be open, and then attempts to discover the location of the REST API. The REST API isn't immediately advertised via the link header, so discovery fails and the tests are not run.

> gutenberg@18.3.0 test:e2e
> wp-scripts test-playwright --config test/e2e/playwright.config.ts

Error: Failed to discover REST API endpoint.
 Link header: undefined

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

  30 |
  31 | 	if ( ! restLink ) {
> 32 | 		throw new Error( `Failed to discover REST API endpoint.
     | 		      ^
  33 |  Link header: ${ links }` );
  34 | 	}
  35 |

    at getAPIRootURL (.../packages/e2e-test-utils-playwright/src/request-utils/rest.ts:32:9)
    at RequestUtils.setupRest (.../packages/e2e-test-utils-playwright/src/request-utils/rest.ts:42:29)
    at globalSetup (.../test/e2e/config/global-setup.ts:26:2)

Metadata

Metadata

Assignees

Labels

[Status] In ProgressTracking issues with work in progress[Tool] WP Scripts/packages/scripts[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions