| name | e2e-test-runner |
| description | Runs and debugs Detox E2E tests for MigraineTracker React Native app. Use when the user asks to run E2E tests, debug test failures, or investigate UI test issues. Automatically captures logs, analyzes screenshots, and diagnoses common failure patterns. Kills tests early on first failure to save time. |
E2E Test Runner and Debugger
Overview
Specialized skill for running, monitoring, and debugging Detox E2E tests in the MigraineTracker React Native application. Automatically captures diagnostics, analyzes failures, and provides solutions based on known patterns.
When to Use This Skill
Invoke this skill when:
- User asks to run E2E tests or UI tests
- User mentions "test:ui", "detox", or E2E testing
- E2E tests are failing and need debugging
- User asks to investigate test failures
- User mentions screenshots, test artifacts, or test logs
Core Workflow
Step 1: Run Tests with Diagnostics
IMPORTANT: Always capture output and kill tests early on first failure
cd /Users/vfilby/Projects/MigraineTracker/app
npm run test:ui -- e2e/specificTest.test.js 2>&1 | tee /tmp/e2e-test-output.log &
TEST_PID=$!
tail -f /tmp/e2e-test-output.log | grep --line-buffered -E "FAIL|Error|Failed|constraint" &
MONITOR_PID=$!
wait $TEST_PID
TEST_EXIT_CODE=$?
kill $MONITOR_PID 2>/dev/null || true
Key principle: Don't wait for all tests to complete if you see an error. Kill early and investigate immediately.
Step 2: Find Most Recent Test Artifacts
LATEST_ARTIFACTS=$(ls -td app/e2e/artifacts/ios.sim.debug.* 2>/dev/null | head -1)
echo "Latest artifacts: $LATEST_ARTIFACTS"
ls "$LATEST_ARTIFACTS" | grep "✗"
Step 3: Check Multiple Log Sources
Critical: Check ALL of these sources in order:
A. Captured Console Output
grep -A 20 "Failed\|Error code\|constraint" /tmp/e2e-test-output.log
grep -B 5 -A 10 "TestHelpers" /tmp/e2e-test-output.log
grep -E "NOT NULL|foreign key|UNIQUE constraint" /tmp/e2e-test-output.log
B. Detox Log Artifacts
find "$LATEST_ARTIFACTS" -name "*.log" -o -name "*device*"
FAILED_TEST=$(ls "$LATEST_ARTIFACTS" | grep "✗" | head -1)
cat "$LATEST_ARTIFACTS/$FAILED_TEST"/*.log 2>/dev/null
C. Screenshots (Visual Analysis)
find "$LATEST_ARTIFACTS" -name "*Failure*.png" -o -name "testFnFailure.png"
D. Live Simulator Logs (if needed)
SIMULATOR_ID=$(xcrun simctl list devices | grep "Booted" | grep -oE '[A-F0-9-]{36}' | head -1)
xcrun simctl spawn "$SIMULATOR_ID" log stream \
--predicate 'eventMessage contains "TestHelpers" OR eventMessage contains "Error"' \
--level debug \
2>&1 | tee /tmp/simulator-logs.txt
Step 4: Analyze Failure Patterns
After collecting logs and screenshots, identify the failure pattern. See references/known-issues.md for common patterns and solutions.
Common patterns to look for:
- Database constraint errors (NOT NULL, foreign key, UNIQUE)
- Missing test fixtures ("Test Topiramate" not found)
- Database reset failures
- Navigation issues (wrong screen)
- Timeout waiting for UI elements
Step 5: Kill Tests Early
Don't wait for all tests to finish if you found the error!
pkill -f "jest.*e2e"
kill $TEST_PID
This saves time and gives you the error logs faster.
Step 6: Implement Fix and Verify
After identifying the root cause:
- Implement the fix
- Run ONLY the failing test to verify
- If fixed, run full test suite
npm run test:ui -- e2e/specificTest.test.js
npm run test:ui
Debugging Checklist
When debugging a test failure, systematically check:
Key Detox Commands
npm run test:ui
npm run test:ui -- e2e/medicationTracking.test.js
npm run test:ui:rebuild
xcrun simctl list devices | grep iPhone
xcrun simctl io booted screenshot /tmp/debug-screenshot.png
xcrun simctl spawn booted log collect --output /tmp/sim.logarchive
log show /tmp/sim.logarchive | grep -i error
Important Project Context
Test Infrastructure
- Framework: Detox for E2E testing
- Device: iPhone 16 Pro Max simulator (primary)
- Test Location:
app/e2e/*.test.js
- Artifacts:
app/e2e/artifacts/ios.sim.debug.*
- Deep Links: Tests use
migraine-tracker://test/* for database control
Database Reset Mechanism
Tests reset the database via deep links:
await device.openURL({
url: 'migraine-tracker://test/reset?token=detox&fixtures=true'
});
This is handled by src/utils/testDeepLinks.ts which calls src/utils/testHelpers.ts.
Common Test Fixtures
- Test Topiramate (preventative medication)
- Test Ibuprofen (rescue medication)
- Medication schedules with specific times
- Past episodes for history testing
Output Format
When reporting test results:
If tests pass:
✅ All E2E tests passed
- Test file: [name]
- Duration: [time]
- Tests: [count] passed
If tests fail:
❌ E2E tests failed
Root Cause: [specific error identified]
Location: [file:line or component]
Evidence:
- Console: [relevant log excerpt]
- Screenshot: [what the screenshot shows]
Recommended Fix: [specific code change needed]
Best Practices
- Always capture console output - errors might only appear there
- Kill tests early - don't waste time on subsequent failures
- Read screenshots visually - use Read tool to see UI state
- Check multiple log sources - console, artifacts, simulator
- Look for root cause - don't fix symptoms
- Verify fixes with single test - before running full suite
- Check known issues first - many patterns repeat
Related Files
.detoxrc.js - Detox configuration (artifacts, devices)
e2e/helpers.js - Test helper functions
src/utils/testHelpers.ts - Database reset and fixtures
src/utils/testDeepLinks.ts - Deep link handlers for testing
references/known-issues.md - Common failure patterns