Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: Run E2E tests with WP Playground #62692

Draft
wants to merge 11 commits into
base: trunk
Choose a base branch
from

Conversation

WunderBart
Copy link
Member

@WunderBart WunderBart commented Jun 20, 2024

What?

A simple PoC for running E2E tests against a Playground instance (circumventing wp-env entirely).

How?

  1. Checkout this branch.

Playground part

  1. Clone WP Playground and install deps:

    git clone -b trunk --single-branch --depth 1 git@github.com:WordPress/wordpress-playground.git
    cd wordpress-playground
    npm install
  2. Run the following CLI command to start the Playground server:

    GUTENBERG_PATH=../path/to/your/gutenberg/repo
    
    bun packages/playground/cli/src/cli.ts server \
        --wp=6.5 \
        --mount=$GUTENBERG_PATH:/wordpress/wp-content/plugins/gutenberg \
        --mount=$GUTENBERG_PATH/test/gutenberg-test-themes:/wordpress/wp-content/themes/gutenberg-test-themes \
        --mount=$GUTENBERG_PATH/packages/e2e-tests/mu-plugins:/wordpress/wp-content/mu-plugins \
        --mount=$GUTENBERG_PATH/packages/e2e-tests/plugins:/wordpress/wp-content/plugins/gutenberg-test-plugins \
        --blueprint=$GUTENBERG_PATH/test/e2e/playground.blueprint.json
  3. Note the server URL. By default it's http://127.0.0.1:9400.

Gutenberg part

  1. Run npm run build to build the local Gutenberg.

  2. Assign the Playground server via WP_BASE_URL and run the tests as usual. For example:

    WP_BASE_URL=http://127.0.0.1:9400/ npm run test:e2e
  3. No wp-env, no Docker. Profit?

@WunderBart WunderBart force-pushed the try/run-e2e-tests-against-playground branch 2 times, most recently from 26f785c to f60c136 Compare June 20, 2024 13:38
@WunderBart WunderBart force-pushed the try/run-e2e-tests-against-playground branch from f60c136 to 5416734 Compare June 20, 2024 13:59
@WunderBart WunderBart changed the title PoC: Run E2E tests against WP Playground PoC: Run E2E tests with WP Playground Jun 20, 2024
@WunderBart
Copy link
Member Author

@adamziel, many tests are failing because the database randomly disconnects, causing the app to throw 500 errors. I have yet to find a consistent way to reproduce the issue, but I'll continue working on it when I'm back (around July 2nd). Once this issue is resolved, the legit failures will provide valuable information on Playground's current limitations compared to wp-env.

It's been nice to see how easy it is to circumvent wp-env. Spinning up the WP Playground instance is really fast, too. 💪

cc: @griffbrad @dmsnell

@swissspidy
Copy link
Member

FWIW for https://github.com/swissspidy/media-experiments I always use wp-now for running tests locally (as I can't use Docker) and I constantly run into the same issue with 500 errors. Curious to hear what you find out.


# Install the dependencies
cd playground
npm install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this keeps the Playground updated, but the build artifact from the Playground should be an executable you can download and run directly. That would surely skip a lot of runtime and build steps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run wp-env start
cd playground
~/.bun/bin/bun packages/playground/cli/src/cli.ts server \
--wp=6.5 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be preferable to use nightly here?

@dmsnell
Copy link
Contributor

dmsnell commented Jul 2, 2024

@WunderBart @swissspidy are you using a MySQL connection or relying on SQLite when you get the 500s? How do we know it's a database disconnect? I didn't think that is possible with SQLite, and I wonder also if we're seeing concurrency issues with multiple requests? Mostly the Playground handles requests serially, but I think it should be fine with concurrent requests as well.

@swissspidy
Copy link
Member

Hmm I don't think it's a database issue in my case. Also no idea how to make it use MySQL, so I think it's just the default SQLite setup.

Just did another test and it's actually more a timeout than a proper error 500.

The server stops responding and in the terminal I get errors like this:

Error: PHP.run() failed with exit code 255 and the following output: 
    at _NodePHP.run (/Users/pascalb/Workspace/WordPress/media-experiments/node_modules/@php-wasm/node/index.cjs:72937:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async #dispatchToPHP (/Users/pascalb/Workspace/WordPress/media-experiments/node_modules/@php-wasm/node/index.cjs:72470:14)
    at async PHPRequestHandler.request (/Users/pascalb/Workspace/WordPress/media-experiments/node_modules/@php-wasm/node/index.cjs:72385:14)
    at async PHPBrowser.request (/Users/pascalb/Workspace/WordPress/media-experiments/node_modules/@php-wasm/node/index.cjs:72170:22)
    at async file:///Users/pascalb/Workspace/WordPress/media-experiments/node_modules/@wp-now/wp-now/main.js:945:20 {
  output: {
    stdout: '<!DOCTYPE html>\n' +
      '<html lang="en-US">\n' +
      '<head>\n' +
      '\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n' +
      '\t<meta name="viewport" content="width=device-width">\n' +
      '\t\t',
    stderr: ''
  },
  source: 'request'
}

But I don't wanna hijack the discussion here :-)

Copy link

github-actions bot commented Jul 11, 2024

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: Needs Author's Reply.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Author's Reply
Development

Successfully merging this pull request may close these issues.

None yet

4 participants