|
| 1 | +name: Run Playwright tests |
| 2 | +description: Run E2E tests with browsers from the matching official Playwright image. |
| 3 | +inputs: |
| 4 | + test-script: |
| 5 | + description: Composer script that runs the E2E tests. |
| 6 | + required: true |
| 7 | +runs: |
| 8 | + using: composite |
| 9 | + steps: |
| 10 | + - name: Resolve Playwright version |
| 11 | + id: playwright |
| 12 | + shell: bash |
| 13 | + working-directory: wordpress |
| 14 | + run: | |
| 15 | + node <<'NODE' >> "$GITHUB_ENV" |
| 16 | + const { createRequire } = require( 'node:module' ); |
| 17 | + const { realpathSync } = require( 'node:fs' ); |
| 18 | + const path = require( 'node:path' ); |
| 19 | + const testRequire = createRequire( require.resolve( '@playwright/test/package.json' ) ); |
| 20 | + const playwright = testRequire.resolve( 'playwright/package.json' ); |
| 21 | + console.log( `PLAYWRIGHT_VERSION=${require( playwright ).version}` ); |
| 22 | + console.log( `PLAYWRIGHT_PACKAGE=${path.dirname( playwright )}` ); |
| 23 | + console.log( `PLAYWRIGHT_NODE_MODULES=${realpathSync( 'node_modules' )}` ); |
| 24 | + NODE |
| 25 | +
|
| 26 | + - name: Start Playwright browser server |
| 27 | + shell: bash |
| 28 | + run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" up --wait --wait-timeout 60 |
| 29 | + |
| 30 | + - name: Run E2E tests |
| 31 | + shell: bash |
| 32 | + env: |
| 33 | + TEST_SCRIPT: ${{ inputs.test-script }} |
| 34 | + PW_TEST_CONNECT_WS_ENDPOINT: ws://127.0.0.1:3000/ |
| 35 | + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' |
| 36 | + run: composer run "$TEST_SCRIPT" |
| 37 | + |
| 38 | + - name: Show browser server logs |
| 39 | + if: failure() && steps.playwright.outcome == 'success' |
| 40 | + shell: bash |
| 41 | + run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" logs |
| 42 | + |
| 43 | + - name: Stop Playwright browser server |
| 44 | + if: always() && steps.playwright.outcome == 'success' |
| 45 | + shell: bash |
| 46 | + run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" down |
0 commit comments