diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index dc8e7760..ddee3fdc 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -101,3 +101,60 @@ jobs: - name: Bundle run: pnpm bundle:all + + e2e: + name: "E2E Tests" + if: github.repository == 'wpsocio/wp-projects' + timeout-minutes: 15 + runs-on: ubuntu-latest + + steps: + - name: Checkout this repo + uses: actions/checkout@v4 + with: + token: ${{ secrets.ACCESS_TOKEN_IR }} + + - name: Remote refs + uses: ./actions/upstream-refs + id: remote-refs + + - name: Checkout premium projects repo + uses: actions/checkout@v4 + with: + path: premium + token: ${{ secrets.ACCESS_TOKEN_IR }} + repository: ${{ secrets.PREMIUM_PROJECTS_REPO }} + ref: ${{ fromJSON(steps.remote-refs.outputs.result).premium || 'main' }} + + - name: Setup Environment + uses: ./actions/setup + with: + enable-wireit-cache: true + + - name: Build + run: pnpm build + + - name: Install Playwright dependencies + run: | + npx playwright install chromium firefox webkit --with-deps + + - name: Start WordPress Environment + run: | + pnpm env-start + + - name: Run tests + env: + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 + run: pnpm test:e2e + + - name: Upload debug artifacts + uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: failures-artifacts + path: artifacts/test-results + if-no-files-found: ignore + + - name: Stop WordPress Environment + run: | + pnpm env-stop diff --git a/.gitignore b/.gitignore index 6f75824c..e31b6249 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,6 @@ tsconfig.tsbuildinfo .turbo/ .wireit/ .phpunit.result.cache -/test/e2e/artifacts/ # Misc build/ diff --git a/.wp-env.json b/.wp-env.json index a7b29c9e..6b0fee23 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,4 +1,6 @@ { + "$schema": "https://schemas.wp.org/trunk/wp-env.json", + "core": "WordPress/WordPress", "config": { "WP_DEBUG_LOG": true }, @@ -13,7 +15,9 @@ "tests": { "mappings": { "wp-content/plugins/classic-editor": "WordPress/classic-editor", - "wp-content/mu-plugins": "./test/e2e-mu-plugins" + "wp-content/mu-plugins": "./test/e2e-mu-plugins", + "wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.2.3.zip", + "wp-content/themes/gutenberg-test-themes/twentytwentyfour": "https://downloads.wordpress.org/theme/twentytwentyfour.1.2.zip" } } } diff --git a/test/e2e-mu-plugins/e2e-wp-rest.php b/test/e2e-mu-plugins/e2e-wp-rest.php index 11d0fd20..6a5db474 100644 --- a/test/e2e-mu-plugins/e2e-wp-rest.php +++ b/test/e2e-mu-plugins/e2e-wp-rest.php @@ -1,15 +1,12 @@ { await rest.deleteOption('wptelegram_comments'); }); - test('Should render the widget ', async ({ + test('Should render the comments widget ', async ({ requestUtils, page, editor, @@ -65,7 +65,7 @@ test.describe('Public UI', () => { ); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-comments/v1/settings', + apiPath: '/wptelegram-comments/v1/settings', }); }); @@ -91,7 +91,7 @@ test.describe('Public UI', () => { await page.keyboard.type(`${postId}`); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-comments/v1/settings', + apiPath: '/wptelegram-comments/v1/settings', }); await page.goto(`/?p=${postId}`); @@ -110,7 +110,7 @@ test.describe('Public UI', () => { await page.getByLabel('Exclude').clear(); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-comments/v1/settings', + apiPath: '/wptelegram-comments/v1/settings', }); await page.goto(`/?p=${postId}`); diff --git a/test/e2e/specs/wptelegram-comments/settings-page.spec.ts b/test/e2e/specs/wptelegram-comments/settings-page.spec.ts index b2821d74..9aefc9d2 100644 --- a/test/e2e/specs/wptelegram-comments/settings-page.spec.ts +++ b/test/e2e/specs/wptelegram-comments/settings-page.spec.ts @@ -69,7 +69,7 @@ test.describe('Settings', () => { await page.keyboard.type(''); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-comments/v1/settings', + apiPath: '/wptelegram-comments/v1/settings', assertSaved: true, }); @@ -95,7 +95,7 @@ test.describe('Settings', () => { await page.keyboard.type('1, 2, 3,invalid,'); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-comments/v1/settings', + apiPath: '/wptelegram-comments/v1/settings', }); expect(await page.getByLabel('Code').inputValue()).toBe( diff --git a/test/e2e/specs/wptelegram-login/public-ui.spec.ts b/test/e2e/specs/wptelegram-login/public-ui.spec.ts index 03935673..6009ae85 100644 --- a/test/e2e/specs/wptelegram-login/public-ui.spec.ts +++ b/test/e2e/specs/wptelegram-login/public-ui.spec.ts @@ -35,7 +35,7 @@ test.describe('Public UI', () => { await botUsernameField.fill('E2ETestBot'); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-login/v1/settings', + apiPath: '/wptelegram-login/v1/settings', }); }); diff --git a/test/e2e/specs/wptelegram-login/settings-page.spec.ts b/test/e2e/specs/wptelegram-login/settings-page.spec.ts index f6cc337c..fccb0c3c 100644 --- a/test/e2e/specs/wptelegram-login/settings-page.spec.ts +++ b/test/e2e/specs/wptelegram-login/settings-page.spec.ts @@ -162,7 +162,7 @@ test.describe('Settings', () => { await page.keyboard.type('E2ETestBot'); await actions.saveChangesAndWait({ - apiPath: 'wp-json/wptelegram-login/v1/settings', + apiPath: '/wptelegram-login/v1/settings', assertSaved: true, }); diff --git a/test/e2e/utils/actions.ts b/test/e2e/utils/actions.ts index a2fcc647..a8692661 100644 --- a/test/e2e/utils/actions.ts +++ b/test/e2e/utils/actions.ts @@ -19,7 +19,15 @@ export class Actions { await Promise.all([ saveButton.click(), - this.page.waitForResponse((resp) => resp.url().includes(apiPath)), + this.page.waitForResponse((resp) => { + const url = resp.url(); + + return ( + url.includes(apiPath) || + // API path can be encoded in the URL as `rest_route`. + url.includes(encodeURIComponent(apiPath)) + ); + }), ]); if (assertSaved) {