Skip to content

Commit 6545e20

Browse files
committed
debug
1 parent 39ea959 commit 6545e20

File tree

3 files changed

+53
-292
lines changed

3 files changed

+53
-292
lines changed

tests/e2e/CI-SETUP.md

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

tests/e2e/README.md

Lines changed: 32 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,61 @@
1-
# Playwright Tests for Code Snippets
1+
# Playwright Tests
22

3-
Simple Playwright tests for the Code Snippets WordPress plugin using `@wordpress/env`.
3+
End-to-end tests for Code Snippets using `@wordpress/env`.
44

5-
## 📋 Prerequisites
5+
## Prerequisites
66

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+
109

11-
## 🚀 Quick Start
10+
## Quick Start
1211

13-
### 1. Install Dependencies
1412
```bash
13+
# Install dependencies
1514
npm install
16-
```
1715

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 ..
2318

24-
### 3. Start WordPress Environment
25-
```bash
26-
# Make sure Docker is running first
19+
# Start WordPress environment
2720
npm run wp-env:start
28-
```
2921

30-
### 4. Run Tests
31-
```bash
32-
# Run all tests
22+
# Run tests
3323
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
4924
```
5025

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
6127

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
7028
```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
7835
```
7936

80-
### WordPress Not Starting
81-
```bash
82-
# Check if port 8888 is available
83-
lsof -i :8888
37+
## CI/CD
8438

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
8843

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
9745

98-
### Clean Restart
46+
**Docker not running:**
9947
```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
10849
```
10950

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:**
11352
```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
12155
```
12256

123-
## 📋 Available Commands
124-
57+
**Tests failing:**
12558
```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
13261
```

tests/e2e/code-snippets.spec.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,39 @@ test.describe('Code Snippets Admin Page @admin', () => {
99
});
1010

1111
test('Can add a new snippet', async ({ page }) => {
12-
await page.click('text=Add New')
13-
await page.fill('#title', TEST_SNIPPET_NAME)
14-
await page.fill('.CodeMirror textarea', 'echo "Hello World!";')
15-
await page.click('text=Save Snippet')
16-
await expect(page.locator('#message.notice')).toContainText('Snippet created')
12+
await page.click('text=Add New');
13+
await page.waitForLoadState('networkidle');
14+
15+
// Wait for the form to be ready
16+
await page.waitForSelector('#title');
17+
await page.fill('#title', TEST_SNIPPET_NAME);
18+
19+
// Wait for CodeMirror to be ready
20+
await page.waitForSelector('.CodeMirror textarea');
21+
await page.fill('.CodeMirror textarea', 'echo "Hello World!";');
22+
23+
await page.click('text=Save Snippet');
24+
await expect(page.locator('#message.notice')).toContainText('Snippet created');
1725
});
1826

1927
test('Can activate and deactivate a snippet', async ({ page }) => {
28+
// Wait for the snippet to exist before clicking
29+
await page.waitForSelector(`text=${TEST_SNIPPET_NAME}`);
2030
await page.click(`text=${TEST_SNIPPET_NAME}`);
31+
await page.waitForLoadState('networkidle');
32+
2133
await page.click('text=Save and Activate');
2234
await expect(page.locator('#message.notice p')).toContainText('Snippet updated and activated.');
2335
await page.click('text=Save and Deactivate');
2436
await expect(page.locator('#message.notice p')).toContainText('Snippet updated and deactivated');
2537
});
2638

2739
test('Can delete a snippet', async ({ page }) => {
40+
// Wait for the snippet to exist before clicking
41+
await page.waitForSelector(`text=${TEST_SNIPPET_NAME}`);
2842
await page.click(`text=${TEST_SNIPPET_NAME}`);
43+
await page.waitForLoadState('networkidle');
44+
2945
await page.click('text=Delete');
3046
await page.click('button.components-button.is-destructive.is-primary'); // Confirm dialog
3147
await expect(page.locator('body')).not.toContainText(TEST_SNIPPET_NAME);

0 commit comments

Comments
 (0)