๐Ÿงช 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

RoleAddressUse Case
Deployer0xf39Fd6...Jar creation, admin functions
Cookie Monster0x70997970...NFT holder, allowlisted
Cookie Fan0x3C44CdDd...NFT holder, allowlisted
Test User0x90F79bf6...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

  1. Run basic setup test: bun test:e2e basic-setup.spec.ts
  2. Run complete suite: bun test:e2e
  3. Add more test scenarios as needed
  4. 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