feat: Integrate Playwright into docker-compose
Some checks failed
Magnitude Tests / test (push) Failing after 2m2s
Some checks failed
Magnitude Tests / test (push) Failing after 2m2s
Adds Playwright service to docker-compose.yml for easier test execution and better integration with existing database services. ## Changes - Add `playwright` service to docker-compose.yml: - Uses official Playwright image (mcr.microsoft.com/playwright:v1.49.1-noble) - Runs as non-root user (pwuser) for security - Uses host networking to access dev server on localhost:3000 - Loads environment variables from .env - Uses `profiles: [test]` to keep it optional - Mounts node_modules volume to prevent permission issues - Update documentation in AGENTS.md: - Replace standalone Docker commands with docker-compose usage - Document two usage patterns: `docker compose run` and `--profile test` - Explain benefits of integrated setup ## Usage ```bash # Start database services docker compose up -d # Start dev server pnpm dev # Run Playwright tests in Docker docker compose run --rm playwright ``` Or with profiles: ```bash # Run tests one-off docker compose --profile test run --rm playwright ``` ## Benefits - Unified infrastructure setup (database + tests) - No need for separate Dockerfile build step - Easier for new developers to run tests - Consistent with existing docker-compose workflow 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
36
AGENTS.md
36
AGENTS.md
@@ -123,28 +123,40 @@ These credentials should be used for all automated testing (Magnitude, Playwrigh
|
|||||||
|
|
||||||
**Playwright Docker Setup**:
|
**Playwright Docker Setup**:
|
||||||
|
|
||||||
For consistent testing environments across users and CI/CD, use the Playwright Docker image:
|
Playwright is integrated into docker-compose for consistent testing environments:
|
||||||
|
|
||||||
1. **Build the Playwright Docker image**:
|
1. **Run Playwright tests with docker-compose**:
|
||||||
```bash
|
```bash
|
||||||
docker build -f Dockerfile.playwright -t ponderants-playwright .
|
# Start database services
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
# Start Next.js dev server
|
||||||
|
pnpm dev
|
||||||
|
|
||||||
|
# Run Playwright tests in Docker (in another terminal)
|
||||||
|
docker compose run --rm playwright
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Run Playwright tests in Docker**:
|
2. **Alternative: Use the 'test' profile**:
|
||||||
```bash
|
```bash
|
||||||
docker run --rm \
|
# Start all services including Playwright
|
||||||
--network=host \
|
docker compose --profile test up
|
||||||
-v $(pwd):/home/pwuser/app \
|
|
||||||
-e TEST_BLUESKY_HANDLE \
|
# Or run tests one-off without keeping services up
|
||||||
-e TEST_BLUESKY_PASSWORD \
|
docker compose --profile test run --rm playwright
|
||||||
ponderants-playwright
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Benefits**:
|
3. **Benefits**:
|
||||||
- Non-root user execution (pwuser) for security
|
- Non-root user execution (pwuser) for security
|
||||||
- Consistent browser versions across environments
|
- Consistent browser versions across environments
|
||||||
- Isolated test environment
|
- Integrated with existing docker-compose setup
|
||||||
- Ready for CI/CD integration
|
- Uses host networking to access dev server on localhost:3000
|
||||||
|
- Node modules volume prevents permission issues
|
||||||
|
|
||||||
|
4. **Configuration**:
|
||||||
|
- Environment variables loaded from .env file
|
||||||
|
- Uses `network_mode: host` to access dev server
|
||||||
|
- Runs with `profiles: [test]` to keep it optional
|
||||||
|
|
||||||
**CI/CD with Gitea Actions**:
|
**CI/CD with Gitea Actions**:
|
||||||
|
|
||||||
|
|||||||
@@ -32,3 +32,26 @@ services:
|
|||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
- surrealdb
|
- surrealdb
|
||||||
|
|
||||||
|
playwright:
|
||||||
|
image: mcr.microsoft.com/playwright:v1.49.1-noble
|
||||||
|
working_dir: /home/pwuser/app
|
||||||
|
user: pwuser
|
||||||
|
network_mode: host
|
||||||
|
volumes:
|
||||||
|
- .:/home/pwuser/app
|
||||||
|
- /home/pwuser/app/node_modules
|
||||||
|
environment:
|
||||||
|
- TEST_BLUESKY_HANDLE=${TEST_BLUESKY_HANDLE}
|
||||||
|
- TEST_BLUESKY_PASSWORD=${TEST_BLUESKY_PASSWORD}
|
||||||
|
- PLAYWRIGHT_BASE_URL=${PLAYWRIGHT_BASE_URL:-http://localhost:3000}
|
||||||
|
command: >
|
||||||
|
sh -c "
|
||||||
|
npm install -g pnpm &&
|
||||||
|
pnpm install --frozen-lockfile &&
|
||||||
|
npx playwright test
|
||||||
|
"
|
||||||
|
depends_on:
|
||||||
|
- surrealdb
|
||||||
|
profiles:
|
||||||
|
- test
|
||||||
|
|||||||
Reference in New Issue
Block a user