|
1 | | -# Playwright Tests for Code Snippets |
| 1 | +# Playwright Tests |
2 | 2 |
|
3 | | -Simple Playwright tests for the Code Snippets WordPress plugin using `@wordpress/env`. |
| 3 | +End-to-end tests for Code Snippets using `@wordpress/env`. |
4 | 4 |
|
5 | | -## 📋 Prerequisites |
| 5 | +## Prerequisites |
6 | 6 |
|
7 | | -- **Docker**: wp-env requires Docker to be running |
8 | | -- **Node.js**: Version 18 or higher |
9 | | -- **npm**: For package management |
| 7 | +- Docker (for wp-env) |
| 8 | +- Node.js 18+ |
10 | 9 |
|
11 | | -## 🚀 Quick Start |
| 10 | +## Quick Start |
12 | 11 |
|
13 | | -### 1. Install Dependencies |
14 | 12 | ```bash |
| 13 | +# Install dependencies |
15 | 14 | npm install |
16 | | -``` |
17 | 15 |
|
18 | | -### 2. Build Plugin and Install PHP Dependencies |
19 | | -```bash |
20 | | -npm run build |
21 | | -cd src && composer install |
22 | | -``` |
| 16 | +# Build plugin and install PHP dependencies |
| 17 | +npm run build && cd src && composer install && cd .. |
23 | 18 |
|
24 | | -### 3. Start WordPress Environment |
25 | | -```bash |
26 | | -# Make sure Docker is running first |
| 19 | +# Start WordPress environment |
27 | 20 | npm run wp-env:start |
28 | | -``` |
29 | 21 |
|
30 | | -### 4. Run Tests |
31 | | -```bash |
32 | | -# Run all tests |
| 22 | +# Run tests |
33 | 23 | npm run test:playwright |
34 | | - |
35 | | -# Run with UI |
36 | | -npm run test:playwright:ui |
37 | | - |
38 | | -# Run in debug mode |
39 | | -npm run test:playwright:debug |
40 | | - |
41 | | -# Run specific test categories |
42 | | -npm run test:playwright -- --grep="@admin" |
43 | | -``` |
44 | | - |
45 | | -### 5. Quick Test Script |
46 | | -```bash |
47 | | -# Run everything with one command |
48 | | -./test-playwright.sh |
49 | 24 | ``` |
50 | 25 |
|
51 | | -## 📁 Test Structure |
52 | | - |
53 | | -- `admin-page.spec.ts` - Tests for the main admin page (@admin) |
54 | | - |
55 | | -## 🔧 Configuration |
56 | | - |
57 | | -- **WordPress Environment**: `.wp-env.json` |
58 | | -- **Playwright Config**: `tests/playwright/playwright.config.ts` |
59 | | - |
60 | | -## 🎯 What Gets Tested |
| 26 | +## Commands |
61 | 27 |
|
62 | | -- ✅ Admin page loads correctly |
63 | | -- ✅ Functions tab displays and is visible |
64 | | -- ✅ WordPress authentication works |
65 | | -- ✅ Plugin is properly activated |
66 | | - |
67 | | -## 🛠️ Troubleshooting |
68 | | - |
69 | | -### Docker Issues |
70 | 28 | ```bash |
71 | | -# Check if Docker is running |
72 | | -docker --version |
73 | | -docker ps |
74 | | - |
75 | | -# Start Docker Desktop (if installed) |
76 | | -# Or start Docker service on Linux |
77 | | -sudo systemctl start docker |
| 29 | +npm run wp-env:start # Start WordPress |
| 30 | +npm run wp-env:stop # Stop WordPress |
| 31 | +npm run wp-env:clean # Clean environment |
| 32 | +npm run test:playwright # Run tests |
| 33 | +npm run test:playwright:ui # Run with UI |
| 34 | +npm run test:playwright:debug # Debug mode |
78 | 35 | ``` |
79 | 36 |
|
80 | | -### WordPress Not Starting |
81 | | -```bash |
82 | | -# Check if port 8888 is available |
83 | | -lsof -i :8888 |
| 37 | +## CI/CD |
84 | 38 |
|
85 | | -# Stop any existing wp-env |
86 | | -npm run wp-env:stop |
87 | | -``` |
| 39 | +Tests run automatically on: |
| 40 | +- Pull requests with `run-tests` label |
| 41 | +- Push to `core` branch |
| 42 | +- Manual workflow dispatch |
88 | 43 |
|
89 | | -### Tests Failing |
90 | | -```bash |
91 | | -# Run with debug output |
92 | | -npm run test:playwright:debug |
93 | | - |
94 | | -# Check WordPress is running |
95 | | -curl http://localhost:8888/wp-admin/ |
96 | | -``` |
| 44 | +## Troubleshooting |
97 | 45 |
|
98 | | -### Clean Restart |
| 46 | +**Docker not running:** |
99 | 47 | ```bash |
100 | | -# Stop WordPress |
101 | | -npm run wp-env:stop |
102 | | - |
103 | | -# Clean environment |
104 | | -npm run wp-env:clean |
105 | | - |
106 | | -# Start fresh |
107 | | -npm run wp-env:start |
| 48 | +docker --version && docker ps |
108 | 49 | ``` |
109 | 50 |
|
110 | | -### Alternative: Test Against Existing WordPress Site |
111 | | -If you don't want to use Docker, you can test against an existing WordPress site: |
112 | | - |
| 51 | +**WordPress won't start:** |
113 | 52 | ```bash |
114 | | -# Set environment variables |
115 | | -export WP_URL=http://your-wordpress-site.local |
116 | | -export WP_USERNAME=admin |
117 | | -export WP_PASSWORD=password |
118 | | - |
119 | | -# Run tests against existing site |
120 | | -npm run test:playwright |
| 53 | +lsof -i :8888 # Check port availability |
| 54 | +npm run wp-env:stop && npm run wp-env:start |
121 | 55 | ``` |
122 | 56 |
|
123 | | -## 📋 Available Commands |
124 | | - |
| 57 | +**Tests failing:** |
125 | 58 | ```bash |
126 | | -npm run wp-env:start # Start WordPress environment |
127 | | -npm run wp-env:stop # Stop WordPress environment |
128 | | -npm run wp-env:clean # Clean WordPress environment |
129 | | -npm run test:playwright # Run all tests |
130 | | -npm run test:playwright:ui # Run with UI |
131 | | -npm run test:playwright:debug # Run in debug mode |
| 59 | +npm run test:playwright:debug |
| 60 | +curl http://localhost:8888/wp-admin/ # Check WordPress |
132 | 61 | ``` |
0 commit comments