๐งช E2E Testing
November 16, 2025 ยท View on GitHub
Playwright end-to-end testing for Cookie Jar protocol, designed to work seamlessly with the existing development environment.
๐ Quick Start
# Terminal 1: Start development environment
bun dev
# Terminal 2: Run tests
bun test:e2e # Run all E2E tests
bun test:e2e:ui # Visual test runner
bun test:e2e:debug # Debug mode
๐ Test Structure
e2e/
โโโ basic-setup.spec.ts # Basic functionality verification
โโโ jar-creation.spec.ts # Jar creation workflows
โโโ jar-operations.spec.ts # Deposits, withdrawals, access control
โโโ admin-functions.spec.ts # Admin functionality (allowlist, NFT gates)
โโโ complete-workflow.spec.ts # End-to-end jar lifecycle
โโโ accessibility.spec.ts # Accessibility compliance
โโโ performance.spec.ts # Performance testing
โโโ utils/
โโโ constants.ts # Test accounts and selectors
โโโ wallet-utils.ts # Wallet testing utilities
โโโ global-setup.ts # Test environment setup
โโโ global-teardown.ts # Cleanup
๐ Test Accounts
| Role | Address | Use Case |
|---|---|---|
| Deployer | 0xf39Fd6... | Jar creation, admin functions |
| Cookie Monster | 0x70997970... | NFT holder, allowlisted |
| Cookie Fan | 0x3C44CdDd... | NFT holder, allowlisted |
| Test User | 0x90F79bf6... | Non-allowlisted, no NFTs |
๐ฏ Test Categories
๐ข Basic Setup: Homepage loading, navigation, environment verification
๐ก Core Functions: Jar creation, deposits/withdrawals, access control
๐ด Admin Functions: Allowlist management, NFT gates, metadata updates
โฟ Accessibility: WCAG compliance, keyboard navigation, screen reader
โก Performance: Load times, cache efficiency, memory monitoring
๐ ๏ธ Wallet Testing
Simulated wallet approach: Injects wallet state, simulates transactions, triggers wagmi events
Benefits: Fast (no extensions), reliable (consistent), realistic (actual behavior), CI-friendly
๐งญ Running Specific Tests
# Run only jar creation tests
bun test:e2e jar-creation.spec.ts
# Run only admin function tests
bun test:e2e admin-functions.spec.ts
# Run accessibility tests only
bun test:accessibility
# Run with browser visible (for debugging)
bun test:e2e:headed
# Generate HTML report
bun test:e2e:report
๐ง Troubleshooting
Development Environment Not Ready
# Make sure dev environment is running
bun dev
# Check services are ready
curl http://localhost:3000 # Client should respond
curl -X POST http://127.0.0.1:8545 # Anvil should respond
Tests Failing
# Run with debug mode
bun test:e2e:debug
# Check browser console for errors
bun test:e2e:headed
# View detailed HTML report
bun test:e2e:report
Slow Performance
# Run single test file
bun test:e2e basic-setup.spec.ts
# Check if dev environment is properly started
ps aux | grep anvil
ps aux | grep "next dev"
๐ Expected Test Results
Performance Targets:
- Homepage load: < 5 seconds
- Jar list render: < 8 seconds
- Cache loads: < 2 seconds
- Mobile loads: < 8 seconds
Coverage Goals:
- โ Critical user paths: 100%
- โ Admin functions: 100%
- โ Access control: 100%
- โ Error handling: 80%
Browser Support:
- โ Desktop Chrome (primary)
- โ Mobile Chrome
- โ Desktop Firefox (secondary)
- โ Desktop Safari (secondary)
๐ Next Steps
- Run basic setup test:
bun test:e2e basic-setup.spec.ts - Run complete suite:
bun test:e2e - Add more test scenarios as needed
- Integrate with CI/CD pipeline
๐ก Test Writing Tips
Use Robust Selectors
// โ
Good - Multiple fallback strategies
await page.click('button:has-text("Deposit"), .deposit-button, [data-testid="deposit"]')
// โ Fragile - CSS class only
await page.click('.bg-orange-500.px-4')
Handle Async Operations
// โ
Good - Proper timeout for blockchain operations
await expect(page.locator('text=successful')).toBeVisible({ timeout: 30000 })
// โ Bad - No timeout
await page.click('button')
Test Real User Flows
// โ
Good - Complete user journey
test('User creates and funds jar', async ({ page, wallet }) => {
// End-to-end flow
})
// โ Bad - Implementation details
test('Hook returns correct state', async () => {
// This should be a unit test
})
This setup integrates seamlessly with your existing development environment and requires minimal changes to your components!
Additional Resources
- Testing Guide - Comprehensive testing strategy
- Development Guide - Development workflow
- Main Project README: ../README.md - Setup and overview