Testing & Quality Assurance
Mind Measure uses a comprehensive testing and quality assurance system to prevent regressions and ensure code quality.
Overview
After a critical incident on December 8, 2025, we implemented a multi-layered prevention system that includes:
- Automated Layout Verification - Runs on every deployment
- Visual Regression Testing - Catches UI changes automatically
- Pre-Commit Hooks - Blocks problematic code before it's committed
- Architecture Decision Records - Documents major technical decisions
- Safe Rollback Procedures - Prevents dangerous rollbacks
Quick Reference
Running Tests
# Check critical layout elements
npm run check-layout
# Visual regression tests
npm run test:visual
# E2E smoke tests
npm run test:e2e
# All tests
npm run test:all
# Interactive test UI
npm run test:uiPre-Deployment Checklist
Before deploying to production:
- ✅ Run
npm run check-layout- Verifies critical UI elements - ✅ Run
npm run test:visual- Checks for visual regressions - ✅ Run
npm run test:e2e- Validates critical flows - ✅ Check for linter errors
- ✅ Review git diff for unintended changes
Testing Infrastructure
Layout Verification
File: scripts/check-layout.js
Automatically verifies:
- SDK versions are compatible (no mixing of old and new)
- Critical UI text is correct ("Five questions", not "Six")
- Required components are imported correctly
- Essential props are present
Runs automatically:
- Before every deployment (
predeployscript) - On every commit (if Husky is installed)
Visual Regression Tests
Tool: Playwright
What it tests:
- Baseline welcome screen layout
- "What to expect" screen content and spacing
- Conversation UI appearance
- Button positioning and separation
- Responsive layouts on mobile
Configuration: playwright.config.ts
Tests: tests/visual/baseline-flow.spec.ts
E2E Smoke Tests
What it validates:
- App loads without errors
- No critical console errors
- Components render correctly
- No missing assets
- Responsive layout works
- Developer mode triggers correctly
Tests: tests/e2e/smoke-tests.spec.ts
Installation Guide
Step 1: Install Playwright
# Clean npm cache if needed
npm cache clean --force
# Install Playwright
npm install -D @playwright/test --legacy-peer-deps
# Install browser
npx playwright install chromiumStep 2: Install Husky (Optional)
# Install Husky
npm install -D husky
# Initialize
npx husky install
# Set up auto-install
npm pkg set scripts.prepare="husky install"Step 3: Generate Baseline Screenshots
# Start dev server
npm run dev
# Generate reference screenshots
npx playwright test --update-snapshotsStep 4: Verify Installation
# Test layout checks
npm run check-layout
# Test visual regression
npm run test:visual
# Test pre-commit hook
echo "test" > test.txt
git add test.txt
git commit -m "test"Common Scenarios
Updating Visual Baselines
When you intentionally change the UI:
# Update all snapshots
npm run test:visual -- --update-snapshots
# Update specific test
npx playwright test tests/visual/baseline-flow.spec.ts --update-snapshotsBypassing Pre-Commit Hooks
Use sparingly! Only when you know what you're doing:
git commit --no-verify -m "emergency fix"Debugging Test Failures
# Run tests in UI mode (interactive)
npm run test:ui
# Run tests with debug output
DEBUG=pw:api npm run test:visual
# View test report
npx playwright show-reportCI/CD Integration
Vercel Configuration
Build Command:
npm run check-layout && npm run buildInstall Command:
npm ci && npx playwright install chromium --with-depsGitHub Actions
Example workflow:
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run layout checks
run: npm run check-layout
- name: Install Playwright
run: npx playwright install chromium --with-deps
- name: Run tests
run: npm run test:all
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: playwright-report/Troubleshooting
Playwright Won't Install
Error: ENOTEMPTY: directory not empty
Solutions:
# Option 1: Use legacy peer deps
npm install -D @playwright/test --legacy-peer-deps
# Option 2: Clean install
rm -rf node_modules package-lock.json
npm install
# Option 3: Use yarn
yarn add -D @playwright/testPre-Commit Hook Not Running
Solutions:
# Check if hook is executable
chmod +x .husky/pre-commit
# Verify Git hooks path
git config core.hooksPath
# Should output: .husky
# Reinstall Husky
npx husky installTests Fail After UI Changes
This is expected! Review the visual diff:
# Run in UI mode to see differences
npm run test:ui
# If changes are intentional, update baselines
npm run test:visual -- --update-snapshotsBest Practices
Writing New Tests
- Focus on critical user flows - Don't test everything, test what matters
- Use descriptive test names - "shows exactly five questions" not "test1"
- Allow for minor differences - Use
maxDiffPixelsfor visual tests - Test responsiveness - Include mobile viewport tests
- Document expected behavior - Add comments explaining WHY
Maintaining Tests
- Update baselines after intentional changes - Don't ignore failing tests
- Review visual diffs carefully - Ensure changes are intentional
- Keep tests fast - Mock external APIs, use small datasets
- Run tests locally before pushing - Don't rely only on CI
- Fix flaky tests immediately - Flaky tests erode confidence
Test Coverage Goals
- ✅ Critical user flows: 100% (baseline, check-in, dashboard)
- ✅ Major UI components: All tested visually
- ✅ SDK integrations: Error handling tested
- ⏳ Unit tests: Target 70%+ for utilities and helpers
Related Documentation
- Development Safeguards - Complete prevention system
- Rollback Procedures - Safe rollback checklist
- Architecture Decision Records - Technical decision documentation
- Post-Mortem: Dec 8 Incident - What went wrong and how we fixed it
Success Metrics
The testing system is working when:
✅ Bad commits are blocked at commit time
✅ Visual regressions are caught before production
✅ Deployment failures are rare
✅ Rollbacks are safe and documented
✅ Zero "multi-hour debugging sessions"
Last Updated: December 8, 2025
Maintained By: Development Team
Status: ✅ Active and Working