Skip to content

Add basic e2e tests#811

Open
mikachan wants to merge 16 commits intotrunkfrom
add/e2e-tests
Open

Add basic e2e tests#811
mikachan wants to merge 16 commits intotrunkfrom
add/e2e-tests

Conversation

@mikachan
Copy link
Member

This adds basic e2e tests to this repo. The tests cover the two main plugin entry points:

  • Site Editor Sidebar (specs/editor-sidebar.spec.js): Verifies the Site Editor loads and the "Create Block Theme" toolbar button is present.
  • Admin Landing Page (specs/landing-page.spec.js): Verifies the page loads, the Export button is visible, the "Create Blank Theme" modal opens with a name field, and the full create-blank-theme flow completes end-to-end.

Also adds an e2e job to the CI workflow that spins up wp-env, runs the e2e tests, and uploads the artifacts on failure. Adds test:e2e and test:e2e:ui npm scripts and gitignores the artifacts/ directory.

# Conflicts:
#	.github/workflows/pr-checks.yml
#	package-lock.json
#	package.json
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds basic end-to-end (e2e) test infrastructure to the Create Block Theme plugin using Playwright and @wordpress/e2e-test-utils-playwright. The tests verify the two main plugin entry points: the Site Editor sidebar toolbar button and the Admin Landing Page functionality including theme creation workflows.

Changes:

  • Added e2e test infrastructure with Playwright configuration
  • Added two test suites covering the Site Editor sidebar and Admin Landing Page
  • Added e2e job to the CI workflow to run tests automatically

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
specs/landing-page.spec.js Test suite for the admin landing page covering page load, export button, and blank theme creation workflow
specs/editor-sidebar.spec.js Test suite for the Site Editor sidebar verifying the plugin toolbar button appears
playwright.config.js Playwright configuration using WordPress scripts defaults with wp-env test port
package.json Added @wordpress/e2e-test-utils-playwright dependency and npm scripts for running e2e tests
package-lock.json Lock file update for new e2e testing dependency
.gitignore Added artifacts/ directory to ignore Playwright test artifacts
.github/workflows/pr-checks.yml Added e2e job to CI workflow that runs tests in wp-env and uploads artifacts on failure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@jeryj jeryj left a comment

Choose a reason for hiding this comment

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

I tried testing this with a fresh install:

  • npm install
  • npm run build
  • npm run test:e2e

And all the e2e tests passed. Then I tried running some of the tests in isolation and got a failure on "Create Block Theme — Admin Landing Page › create blank theme end-to-end". After the failure started, I couldn't get the test to pass anymore. I think it's a test cleanup thing, because it's failing due to the "Theme already exists" message.

npx playwright failure with theme already exists message in modal

Also, the timeout for the test is really long (100000ms) so it takes a minute and 40 seconds for the test to fail. I'm not sure what Gutenbergs is, but I feel sure it's less than that. I imagine 10 seconds is probably plenty enough for most actions?

Thanks for adding e2e tests to this! 🙌🏻

Comment on lines 27 to 29
execSync(
`npx wp-env run cli wp theme delete ${ E2E_THEME_SLUG }`,
{ stdio: 'ignore' }
Copy link

Choose a reason for hiding this comment

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

I haven't seen a need for this before. Could you explain why this is needed? Is there a precedence for this in Gutenberg already?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no deleteTheme() method available in @wordpress/e2e-test-utils-playwright, and the REST API doesn't support theme deletion (/wp/v2/themes is read-only). Because we're testing this plugin creating a theme, I think WP-CLI is the best way to clean them up.

wp-env is already running at this point, so npx wp-env run cli should be OK to use here.

} )
.click();

await page.waitForURL( /site-editor/ );
Copy link

Choose a reason for hiding this comment

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

Could we assert some kind of success? How do we know if it worked correctly besides going to the site-editor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, makes sense! I've added a test for the theme being activated in f76d4d9.

Comment on lines +13 to +14
page.getByRole( 'button', { name: 'Create Block Theme' } )
).toBeVisible();
Copy link

Choose a reason for hiding this comment

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

Could we test that it works? What does it do when you click it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added a test for opening the sidebar in 4665e2e.

Comment on lines 51 to 53
await expect(
page.getByRole( 'button', { name: /Export/ } )
).toBeVisible();
Copy link

Choose a reason for hiding this comment

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

Can we assert that it works when clicked?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a test to ensure that the export was downloaded successfully: 040ed22.

await expect( page.getByLabel( /Theme name/i ) ).toBeVisible();
} );

test( 'create blank theme end-to-end', async ( { admin, page } ) => {
Copy link

Choose a reason for hiding this comment

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

When I run this test file on its own, this "'create blank theme end-to-end'" test fails: npm run test:e2e specs/landing-page.spec.js

 1) [chromium] › specs/landing-page.spec.js:70:2 › Create Block Theme — Admin Landing Page › create blank theme end-to-end 

    Test timeout of 100000ms exceeded.

    Error: page.waitForURL: Target page, context or browser has been closed
    =========================== logs ===========================
    waiting for navigation until "load"
    ============================================================

      87 | 			.click();
      88 |
    > 89 | 		await page.waitForURL( /site-editor/ );
         | 		           ^
      90 | 	} );
      91 | } );
      92 |

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I've managed to fix this, and when I try npm run test:e2e specs/landing-page.spec.js locally it now passes. It seems like waiting for the full Site Editor to load will take a while, so I've changed it to just check if the navigation has been successful, which should be good enough for this test for now.

@mikachan
Copy link
Member Author

Thanks so much, @jeryj!

Then I tried running some of the tests in isolation and got a failure on "Create Block Theme — Admin Landing Page › create blank theme end-to-end". After the failure started, I couldn't get the test to pass anymore. I think it's a test cleanup thing, because it's failing due to the "Theme already exists" message.

I think this should be fixed now, I'm able to run both test suites independently. Seems like we need to delete the test theme in the beforeAll and the afterAll.

Also, the timeout for the test is really long (100000ms) so it takes a minute and 40 seconds for the test to fail. I'm not sure what Gutenbergs is, but I feel sure it's less than that. I imagine 10 seconds is probably plenty enough for most actions?

We're just using the default timeout settings from @wordpress/scripts here, which I think is what Gutenberg does too. Maybe we could add some overrides here to make them faster.

Copy link

@jeryj jeryj left a comment

Choose a reason for hiding this comment

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

I think there's still something wrong with the cleanup of the theme deletion. I ran these tests:

  1. 🟢 npm run test:e2e specs/landing-page.spec.js
  2. 🟢 npm run test:e2e
  3. 🟢 npm run test:e2e specs/editor-sidebar.spec.js
  4. 🔴 npm run test:e2e specs/landing-page.spec.js

The failure was the same as earlier - "theme already exists".

@jeryj
Copy link

jeryj commented Feb 26, 2026

We're just using the default timeout settings from @wordpress/scripts here

Oh - that's fine then. I looked a little more. I think it's because it's failing while waiting for the site redirection, which has a much longer default. If before the site-editor redirect check, you add a check for the success message, then it fails with a 5000ms timeout instead.

Comment on lines +98 to +102
await page
.getByRole( 'button', {
name: 'Create and Activate Blank Theme',
} )
.click();
Copy link

Choose a reason for hiding this comment

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

Suggested change
await page
.getByRole( 'button', {
name: 'Create and Activate Blank Theme',
} )
.click();
const createThemeButton = page.getByRole( 'button', {
name: 'Create and Activate Blank Theme',
} );
await createThemeButton.click();
await expect( createThemeButton ).toBeHidden();
await expect(
page.getByText(
'Theme created successfully. The editor will now load.'
)
).toBeVisible();

Copy link

Choose a reason for hiding this comment

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

This makes the failure 5000ms instead of 100000ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants