Skip to content

Commit 232f8a8

Browse files
committed
Tests
1 parent 6a7bebb commit 232f8a8

File tree

7 files changed

+703
-29
lines changed

7 files changed

+703
-29
lines changed

.github/workflows/tests.yml

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,106 @@
1-
name: Playwright Tests for WordPress
1+
name: E2E Tests
2+
23
on:
3-
push:
4-
pull_request:
4+
push:
5+
pull_request:
56

67
jobs:
7-
playwright-tests:
8-
runs-on: ubuntu-latest
8+
e2e:
9+
runs-on: ubuntu-latest
10+
services:
11+
mysql:
12+
image: mysql:8.0
13+
env:
14+
MYSQL_DATABASE: wordpress
15+
MYSQL_ROOT_PASSWORD: root
16+
ports: [ 3306:3306 ]
17+
options: >-
18+
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot"
19+
--health-interval=10s
20+
--health-timeout=5s
21+
--health-retries=5
22+
23+
env:
24+
WP_VERSION: 6.5.3
25+
WP_SITE_URL: http://localhost:8888
26+
WP_DB_NAME: wordpress
27+
WP_DB_USER: root
28+
WP_DB_PASS: root
29+
WP_DB_HOST: 127.0.0.1
30+
31+
steps:
32+
- name: Checkout plugin
33+
uses: actions/checkout@v4
34+
35+
- name: Set up PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: 8.2
39+
40+
- name: Install dependencies
41+
run: |
42+
sudo apt-get update
43+
sudo apt-get install -y unzip curl jq
44+
45+
- name: Cache WordPress archive
46+
id: cache-wordpress
47+
uses: actions/cache@v3
48+
with:
49+
path: wordpress
50+
key: wp-${{ env.WP_VERSION }}
51+
52+
- name: Download WordPress
53+
if: steps.cache-wordpress.outputs.cache-hit != 'true'
54+
run: |
55+
curl -O https://wordpress.org/wordpress-${WP_VERSION}.tar.gz
56+
tar -xzf wordpress-${WP_VERSION}.tar.gz
57+
rm wordpress-${WP_VERSION}.tar.gz
58+
59+
- name: Configure WordPress
60+
run: |
61+
cp wordpress/wp-config-sample.php wordpress/wp-config.php
62+
sed -i "s/database_name_here/${WP_DB_NAME}/" wordpress/wp-config.php
63+
sed -i "s/username_here/${WP_DB_USER}/" wordpress/wp-config.php
64+
sed -i "s/password_here/${WP_DB_PASS}/" wordpress/wp-config.php
65+
echo "define( 'DB_HOST', '${WP_DB_HOST}' );" >> wordpress/wp-config.php
66+
echo "define( 'WP_HOME', '${WP_SITE_URL}' );" >> wordpress/wp-config.php
67+
echo "define( 'WP_SITEURL', '${WP_SITE_URL}' );" >> wordpress/wp-config.php
68+
69+
- name: Install WordPress
70+
run: |
71+
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
72+
chmod +x wp-cli.phar
73+
sudo mv wp-cli.phar /usr/local/bin/wp
74+
wp core install \
75+
--url="${WP_SITE_URL}" \
76+
--title="Test Site" \
77+
--admin_user=admin \
78+
--admin_password=admin \
79+
80+
--path=wordpress \
81+
--skip-email \
82+
--allow-root
983
10-
steps:
11-
- name: Checkout Repository
12-
uses: actions/checkout@v4
84+
- name: Install plugin
85+
run: |
86+
PLUGIN_SLUG=$(basename "$GITHUB_WORKSPACE")
87+
ln -s "$GITHUB_WORKSPACE" "wordpress/wp-content/plugins/simpleanalytics"
88+
wp plugin activate simpleanalytics --path=wordpress --allow-root
1389
14-
- name: Set up Node.js
15-
uses: actions/setup-node@v4
16-
with:
17-
node-version: 22
90+
- name: Start PHP server
91+
run: |
92+
php -S localhost:8888 -t wordpress > /dev/null 2>&1 &
93+
sleep 5
1894
19-
- name: Install Dependencies
20-
run: npm install
95+
- name: Setup Node
96+
uses: actions/setup-node@v4
97+
with:
98+
node-version: 20
2199

22-
- name: Install Playwright Browsers
23-
run: npx playwright install --with-deps
100+
- name: Install Playwright and dependencies
101+
run: |
102+
npm ci
103+
npx playwright install --with-deps
24104
25-
# - name: Run Playwright Tests
26-
# env:
27-
# BASE_URL: https://your-wordpress-site.com
28-
# run: npx playwright test
105+
- name: Run Playwright tests
106+
run: npx playwright test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
node*
33
vendor*
44
build
5+
6+
# Playwright
7+
node_modules/
8+
/test-results/
9+
/playwright-report/
10+
/blob-report/
11+
/playwright/.cache/

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2-
"private": true,
3-
"scripts": {
4-
"dev": "tailwindcss -i resources/css/settings.css -o build/css/settings.css --watch",
5-
"build": "tailwindcss build -i resources/css/settings.css -o build/css/settings.css"
6-
},
7-
"devDependencies": {
8-
"@tailwindcss/forms": "^0.5.8",
9-
"tailwindcss": "^3.4.10"
10-
}
2+
"private": true,
3+
"scripts": {
4+
"dev": "tailwindcss -i resources/css/settings.css -o build/css/settings.css --watch",
5+
"build": "tailwindcss build -i resources/css/settings.css -o build/css/settings.css"
6+
},
7+
"devDependencies": {
8+
"@playwright/test": "^1.52.0",
9+
"@tailwindcss/forms": "^0.5.8",
10+
"@types/node": "^22.15.3",
11+
"tailwindcss": "^3.4.10"
12+
}
1113
}

playwright.config.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
/* Run tests in files in parallel */
17+
fullyParallel: true,
18+
/* Fail the build on CI if you accidentally left test.only in the source code. */
19+
forbidOnly: !!process.env.CI,
20+
/* Retry on CI only */
21+
retries: process.env.CI ? 2 : 0,
22+
/* Opt out of parallel tests on CI. */
23+
workers: process.env.CI ? 1 : undefined,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: 'html',
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('/')`. */
29+
// baseURL: 'http://127.0.0.1:3000',
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: 'on-first-retry',
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: 'chromium',
39+
use: { ...devices['Desktop Chrome'] },
40+
},
41+
42+
{
43+
name: 'firefox',
44+
use: { ...devices['Desktop Firefox'] },
45+
},
46+
47+
{
48+
name: 'webkit',
49+
use: { ...devices['Desktop Safari'] },
50+
},
51+
52+
/* Test against mobile viewports. */
53+
// {
54+
// name: 'Mobile Chrome',
55+
// use: { ...devices['Pixel 5'] },
56+
// },
57+
// {
58+
// name: 'Mobile Safari',
59+
// use: { ...devices['iPhone 12'] },
60+
// },
61+
62+
/* Test against branded browsers. */
63+
// {
64+
// name: 'Microsoft Edge',
65+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
66+
// },
67+
// {
68+
// name: 'Google Chrome',
69+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
70+
// },
71+
],
72+
73+
/* Run your local dev server before starting the tests */
74+
// webServer: {
75+
// command: 'npm run start',
76+
// url: 'http://127.0.0.1:3000',
77+
// reuseExistingServer: !process.env.CI,
78+
// },
79+
});

pnpm-lock.yaml

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)