This document provides comprehensive information about the testing infrastructure and how to run tests for the PropChain Web3 platform.
PropChain FrontEnd has a comprehensive testing suite covering:
- Unit Tests: Testing individual functions and components in isolation
- Integration Tests: Testing component interactions and state management
- E2E Tests: Testing complete user workflows across multiple browsers
- Performance Tests: Monitoring application performance and benchmarks
- Jest: Test runner and assertion library
- React Testing Library: Component testing utilities
- @testing-library/user-event: User interaction simulation
- @testing-library/jest-dom: Custom DOM matchers
- Playwright: Cross-browser E2E testing framework
- Multiple Browsers: Chromium, Firefox, WebKit (Safari)
- Mobile Testing: Responsive design validation
- Jest Coverage: Built-in code coverage reporting
- Codecov: Coverage tracking and visualization
- GitHub Actions: Automated CI/CD pipeline
src/
├── __tests__/ # Global test setup
├── components/
│ └── __tests__/ # Component tests
├── store/
│ └── __tests__/ # State management tests
├── utils/
│ └── __tests__/ # Utility function tests
└── types/
└── __tests__/ # Type validation tests
tests/
├── e2e/ # E2E test specifications
├── setup.ts # Global test configuration
└── fixtures/ # Test data and mocks
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Run tests for CI (no watch, coverage enabled)
npm run test:ci# Install Playwright browsers (first time only)
npm run test:e2e:install
# Run E2E tests
npm run test:e2e
# Run E2E tests with UI
npm run test:e2e:ui
# Debug E2E tests
npm run test:e2e:debug# Run performance benchmarks
npm run perf:ci
# Check performance budgets
npm run perf:budgets- Statements: 80%
- Branches: 80%
- Functions: 80%
- Lines: 80%
- Wallet Connection: 100%
- Property Purchase Flow: 95%
- Transaction Processing: 90%
- Error Handling: 85%
- Test One Thing: Each test should verify a single behavior
- Arrange-Act-Assert: Structure tests clearly
- Mock External Dependencies: Use mocks for APIs, Web3 providers
- Test Edge Cases: Cover error states and boundary conditions
- Descriptive Names: Use clear, action-oriented test names
- User Behavior: Test what users see and do
- Accessibility: Include a11y testing
- Responsive Design: Test different viewport sizes
- Error States: Verify error handling and recovery
- Loading States: Test skeleton screens and spinners
- Critical User Journeys: Focus on essential workflows
- Cross-Browser: Test on all supported browsers
- Real Data: Use realistic test data
- Network Conditions: Test slow/fast connections
- Mobile Testing: Verify mobile experience
- Located in
tests/fixtures/ - Includes sample properties, wallets, transactions
- Follows real data structure and constraints
# Test environment
NODE_ENV=test
# Test blockchain configuration
NEXT_PUBLIC_TEST_CHAIN_ID=1337
NEXT_PUBLIC_TEST_RPC_URL=http://localhost:8545- Mock MetaMask, WalletConnect, Coinbase providers
- Test connection states: connecting, connected, error, disconnected
- Verify wallet switching and network changes
- Test transaction signing and confirmation
- Mock contract interactions
- Test transaction states: pending, confirmed, failed
- Verify gas estimation and fee calculation
- Test error handling for insufficient funds, network issues
- Lint & Type Check: Code quality validation
- Unit Tests: Fast feedback on code changes
- E2E Tests: Full workflow validation
- Performance Tests: Regression detection
- Security Audit: Dependency vulnerability scanning
- Coverage Reporting: Track test coverage trends
- Node.js: v18.x, v20.x
- Browsers: Chromium, Firefox, WebKit
- Operating Systems: Ubuntu (CI), local testing
# Run specific test file
npm test -- WalletConnector.test.tsx
# Run specific test
npm test -- --testNamePattern="should display wallet information"
# Debug with Node inspector
node --inspect-brk node_modules/.bin/jest --runInBand# Run with browser UI
npm run test:e2e:ui
# Debug specific test
npx playwright test --debug wallet-connection.spec.ts
# Run with trace files
npx playwright test --trace on- First Contentful Paint (FCP): < 1.5s
- Largest Contentful Paint (LCP): < 2.5s
- Time to Interactive (TTI): < 3.5s
- Cumulative Layout Shift (CLS): < 0.1
- First Input Delay (FID): < 100ms
- JavaScript Bundle Size: < 500KB (compressed)
- CSS Bundle Size: < 100KB (compressed)
- Image Optimization: WebP format, lazy loading
- Font Loading: Preload critical fonts
# Increase Node.js memory limit
NODE_OPTIONS="--max-old-space-size=4096" npm test# Reinstall browsers
npx playwright install --force
# Clear browser cache
npx playwright install --with-deps# Increase timeout
jest.setTimeout(30000)
# Or in test file
test('slow test', async () => {
// test code
}, 30000);- Add Retries: Use
test.retry()for intermittent failures - Wait for Elements: Use
await expect(element).toBeVisible() - Mock Network: Control timing with mocked responses
- Isolate Tests: Run tests independently to identify conflicts
- New components or features
- Bug fixes (regression tests)
- Critical user workflows
- Error handling scenarios
- Test covers happy path
- Test covers error cases
- Test has clear assertions
- Test uses appropriate mocks
- Test follows naming conventions
- Test is maintainable and readable