Skip to content

Commit 8caca2d

Browse files
authored
Merge pull request #13 from alleyinteractive/feature/add-tests
Add playwright tests
2 parents e52e6a9 + 840db52 commit 8caca2d

14 files changed

+248
-29
lines changed

.gitattributes

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
# Via WPCS.
77
#
88
/.github export-ignore
9-
/.phpcs.xml export-ignore
109
/.phpcs export-ignore
11-
/phpunit.xml export-ignore
12-
/tests export-ignore
10+
/.phpcs.xml export-ignore
11+
/.wp-env.json export-ignore
1312
/configure.php export-ignore
1413
/Makefile export-ignore
14+
/package.json export-ignore
15+
/phpstan.neon export-ignore
16+
/phpunit.xml export-ignore
17+
/playwright.config.ts export-ignore
18+
/tests export-ignore
1519

1620
#
1721
# Auto detect text files and perform LF normalization.

.github/workflows/all-pr-tests.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "All Pull Request Tests"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
types: [opened, synchronize, reopened, ready_for_review]
8+
9+
jobs:
10+
# We use a single job to ensure that all steps run in the same environment and
11+
# reduce the number of minutes used.
12+
pr-tests:
13+
# Don't run on draft PRs
14+
if: github.event.pull_request.draft == false
15+
# Timeout after 10 minutes
16+
timeout-minutes: 10
17+
# Define a matrix of PHP/WordPress versions to test against
18+
strategy:
19+
matrix:
20+
php: [8.2, 8.3, 8.4]
21+
wordpress: ["latest"]
22+
runs-on: ubuntu-latest
23+
# Cancel any existing runs of this workflow
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}-P${{ matrix.php }}-WP${{ matrix.wordpress }}
26+
cancel-in-progress: true
27+
# Name the job in the matrix
28+
name: "PR Tests PHP ${{ matrix.php }} WordPress ${{ matrix.wordpress }}"
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Run General Tests
33+
# See https://github.com/alleyinteractive/action-test-general for more options
34+
uses: alleyinteractive/action-test-general@develop
35+
36+
- name: Run PHP Tests
37+
# See https://github.com/alleyinteractive/action-test-php for more options
38+
uses: alleyinteractive/action-test-php@develop
39+
with:
40+
php-version: '${{ matrix.php }}'
41+
wordpress-version: '${{ matrix.wordpress }}'
42+
skip-wordpress-install: 'true'
43+
# This required job ensures that all PR checks have passed before merging.
44+
all-pr-checks-passed:
45+
name: All PR checks passed
46+
needs:
47+
- pr-tests
48+
runs-on: ubuntu-latest
49+
if: always()
50+
steps:
51+
- name: Check job statuses
52+
run: |
53+
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
54+
echo "One or more jobs failed"
55+
exit 1
56+
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
57+
echo "One or more jobs were cancelled"
58+
exit 1
59+
else
60+
echo "All jobs passed or were skipped"
61+
exit 0
62+
fi

.github/workflows/coding-quality.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/coding-standards.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/playwright.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ develop ]
5+
pull_request:
6+
branches: [ develop ]
7+
jobs:
8+
playwright-test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm install
18+
- name: Install Playwright Browsers
19+
run: npx playwright install chromium --with-deps
20+
- name: Install and start wp-env
21+
timeout-minutes: 5
22+
run: |
23+
npm install --global @wordpress/env
24+
wp-env start
25+
26+
# Wait for the server to be ready
27+
while ! curl -s http://localhost:8888 > /dev/null; do
28+
sleep 1
29+
done
30+
- name: Run Playwright tests
31+
run: npx playwright test
32+
- uses: actions/upload-artifact@v4
33+
if: ${{ !cancelled() }}
34+
with:
35+
name: playwright-report
36+
path: playwright-report/
37+
retention-days: 30

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ Thumbs.db
2424
*.code-workspace
2525
.idea
2626
.vscode
27+
28+
# Playwright
29+
/test-results/
30+
/playwright-report/
31+
/blob-report/
32+
/playwright/.cache/
33+
34+
# NPM files (this isn't a front-end package that we release)
35+
package-lock.json

.wp-env.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
4+
"lifecycleScripts": {
5+
"afterClean": "./tests/after-setup.sh",
6+
"afterStart": "./tests/after-setup.sh"
7+
},
8+
"plugins": ["."]
9+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"alleyinteractive/alley-coding-standards": "^2.0",
22-
"szepeviktor/phpstan-wordpress": "^1.1"
22+
"szepeviktor/phpstan-wordpress": "^2.0"
2323
},
2424
"config": {
2525
"allow-plugins": {

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "wp-environment-switcher",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"directories": {
6+
"test": "tests"
7+
},
8+
"scripts": {
9+
"start": "wp-env start",
10+
"test": "playwright test"
11+
},
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@playwright/test": "^1.53.2",
15+
"@types/node": "^24.0.9",
16+
"@wordpress/e2e-test-utils-playwright": "^1.26.0"
17+
}
18+
}

playwright.config.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: './tests',
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Opt out of parallel tests on CI. */
15+
workers: process.env.CI ? 1 : undefined,
16+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
17+
reporter: 'html',
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
/* Base URL to use in actions like `await page.goto('/')`. */
21+
baseURL: 'http://localhost:8888',
22+
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: 'on-first-retry',
25+
},
26+
27+
/* Configure projects for major browsers */
28+
projects: [
29+
{
30+
name: 'chromium',
31+
use: { ...devices['Desktop Chrome'] },
32+
},
33+
],
34+
35+
/* Run your local dev server before starting the tests */
36+
webServer: {
37+
command: 'npx wp-env start',
38+
ignoreHTTPSErrors: true,
39+
reuseExistingServer: true,
40+
stderr: 'pipe',
41+
stdout: 'pipe',
42+
timeout: 60 * 5 * 1000, // 5 minutes
43+
url: 'http://localhost:8888',
44+
},
45+
});

0 commit comments

Comments
 (0)