mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-06 20:32:55 +08:00
* test: add E2E tests for auto-reply trigger and webhook trigger - Improve mock reply() in e2e_test_api.ts to send auto-replies via SMTP (WorkerMailer) so they reach Mailpit for verification - Add auto-reply-trigger.spec.ts: verifies auto-reply is sent when incoming mail matches source_prefix, and NOT sent otherwise - Add webhook-trigger.spec.ts: starts a temporary HTTP server to receive webhook calls, verifies payload on mail arrival Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: fallback EmailMessage for E2E auto-reply when cloudflare:email is unavailable In wrangler dev mode without Email Routing binding, `import('cloudflare:email')` throws, silently caught by auto_reply's try-catch. Add a fallback that constructs a plain object with a ReadableStream `raw` property so the E2E mock reply() can send the auto-reply via SMTP to Mailpit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: handle both \r\n and \n line endings in MIME parser for E2E tests mimetext uses os.EOL which is \n on Linux (Docker). The parseMimeForReply function only looked for \r\n, causing it to fail parsing the auto-reply MIME content in the E2E environment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add debug logging and robust raw MIME extraction for E2E auto-reply - auto_reply.ts: add fallback ReadableStream when cloudflare:email is unavailable, attach rawMime directly to replyMessage - e2e_test_api.ts: try reading rawMime string first, then fallback to ReadableStream; add diagnostic console.log for CI debugging Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: skip sealed EmailMessage in E2E mode, await webhook server listen - auto_reply.ts: use plain object with raw ReadableStream in E2E_TEST_MODE (cloudflare:email's EmailMessage is sealed, can't attach extra properties) - e2e_test_api.ts: simplify mock reply() to read raw ReadableStream directly, add defensive check for from without @ - webhook-trigger.spec.ts: await server.listen to ensure socket is bound before sending requests (CodeRabbit review feedback) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add missing await for async startWebhookReceiver in disabled test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: drop auto-reply E2E test, clean up webhook test - Remove auto-reply-trigger.spec.ts (cannot test without modifying production auto_reply.ts due to sealed EmailMessage from cloudflare:email) - Clean up e2e_test_api.ts: remove WorkerMailer, MIME parsing, and SMTP reply logic that was only needed for auto-reply testing - Improve webhook test: use dynamic port allocation (port 0) instead of hardcoded WEBHOOK_PORT to avoid port conflicts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: assert webhook request path in E2E test Add path assertion to verify webhook request hits /webhook endpoint, preventing false positives from incorrect routing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
E2E Tests
End-to-end tests for Cloudflare Temp Email using Playwright and Mailpit, fully containerized with Docker Compose.
Prerequisites
- Docker and Docker Compose
Quick Start
cd e2e
# Build, start all services, run tests, and exit
npm test
# Clean up containers and volumes
npm run test:down
npm test runs docker compose up --build, which:
- Starts Mailpit (SMTP on :1025, HTTP API on :8025)
- Builds and starts the Worker (wrangler dev on :8787)
- Builds and starts the Frontend (vite dev on :5173)
- Builds and runs the E2E runner (Playwright), which waits for services, initializes the DB, and runs all tests
The exit code reflects the test result.
Test Structure
| Project | Directory | What it tests |
|---|---|---|
api |
tests/api/ |
Worker API endpoints — health check, address CRUD, send mail via SMTP |
browser |
tests/browser/ |
Frontend UI — login, inbox view, reply with HTML, XSS sanitization |
Services
| Service | Container | Port | Purpose |
|---|---|---|---|
| Mailpit SMTP | mailpit |
1025 | Captures outgoing emails |
| Mailpit HTTP | mailpit |
8025 | API to verify captured emails |
| Worker | worker |
8787 | Backend API with E2E config |
| Frontend | frontend |
5173 | Vue frontend dev server |
Test Results
Test results and HTML reports are exported via volumes:
e2e/test-results/— test artifactse2e/playwright-report/— HTML report
Configuration
The E2E worker uses fixtures/wrangler.toml.e2e with:
E2E_TEST_MODE = true— enables test seed endpointDISABLE_ADMIN_PASSWORD_CHECK = true— allows unauthenticated admin callsDEFAULT_SEND_BALANCE = 10— allows sending without admin approval- SMTP pointed at Mailpit container (
mailpit:1025)