1+ name : Visual Regression Testing
2+
3+ on :
4+ pull_request :
5+ branches : [ master ]
6+ paths :
7+ - ' src/**'
8+ - ' tests/visual/**'
9+ - ' package.json'
10+ - ' yarn.lock'
11+
12+ jobs :
13+ visual-regression :
14+ name : Visual Regression Tests
15+ runs-on : ubuntu-latest
16+
17+ steps :
18+ - name : Checkout PR code
19+ uses : actions/checkout@v4
20+ with :
21+ fetch-depth : 0
22+
23+ - name : Setup Node.js
24+ uses : actions/setup-node@v4
25+ with :
26+ node-version : ' 18'
27+ cache : ' yarn'
28+
29+ - name : Install dependencies
30+ run : yarn install --frozen-lockfile
31+
32+ - name : Install system dependencies for Puppeteer
33+ run : |
34+ sudo apt-get update
35+ sudo apt-get install -y \
36+ ca-certificates \
37+ fonts-liberation \
38+ libappindicator3-1 \
39+ libasound2 \
40+ libatk-bridge2.0-0 \
41+ libatk1.0-0 \
42+ libc6 \
43+ libcairo2 \
44+ libcups2 \
45+ libdbus-1-3 \
46+ libexpat1 \
47+ libfontconfig1 \
48+ libgbm1 \
49+ libgcc1 \
50+ libglib2.0-0 \
51+ libgtk-3-0 \
52+ libnspr4 \
53+ libnss3 \
54+ libpango-1.0-0 \
55+ libpangocairo-1.0-0 \
56+ libstdc++6 \
57+ libx11-6 \
58+ libx11-xcb1 \
59+ libxcb1 \
60+ libxcomposite1 \
61+ libxcursor1 \
62+ libxdamage1 \
63+ libxext6 \
64+ libxfixes3 \
65+ libxi6 \
66+ libxrandr2 \
67+ libxrender1 \
68+ libxss1 \
69+ libxtst6 \
70+ lsb-release \
71+ wget \
72+ xdg-utils
73+
74+ - name : Setup Expo CLI
75+ run : npm install -g @expo/cli
76+
77+ - name : Create baseline directory
78+ run : mkdir -p baselines/screenshots
79+
80+ - name : Checkout base branch baselines
81+ run : |
82+ git fetch origin ${{ github.event.pull_request.base.ref }}
83+ git checkout origin/${{ github.event.pull_request.base.ref }} -- baselines/ || echo "No baselines found in base branch"
84+
85+ - name : Start Expo server
86+ run : |
87+ yarn start --web &
88+ echo $! > expo_pid.txt
89+ timeout 120 bash -c 'until curl -f http://localhost:8081 > /dev/null 2>&1; do sleep 2; done'
90+ env :
91+ CI : true
92+ EXPO_NO_DOTENV : true
93+
94+ - name : Run visual tests
95+ run : yarn test:visual:headless
96+ env :
97+ CI : true
98+
99+ - name : Stop Expo server
100+ if : always()
101+ run : |
102+ if [ -f expo_pid.txt ]; then
103+ kill $(cat expo_pid.txt) || true
104+ rm expo_pid.txt
105+ fi
106+
107+ - name : Compare screenshots
108+ run : |
109+ if [ -d "baselines/screenshots" ] && [ -d "test-results/screenshots" ]; then
110+ echo "Comparing screenshots..."
111+ # Create a simple comparison report
112+ for baseline in baselines/screenshots/*.png; do
113+ if [ -f "$baseline" ]; then
114+ filename=$(basename "$baseline")
115+ if [ -f "test-results/screenshots/$filename" ]; then
116+ echo "✅ Found matching screenshot: $filename"
117+ else
118+ echo "❌ Missing screenshot in test results: $filename"
119+ fi
120+ fi
121+ done
122+
123+ for result in test-results/screenshots/*.png; do
124+ if [ -f "$result" ]; then
125+ filename=$(basename "$result")
126+ if [ ! -f "baselines/screenshots/$filename" ]; then
127+ echo "🆕 New screenshot detected: $filename"
128+ fi
129+ fi
130+ done
131+ else
132+ echo "No baseline screenshots found for comparison"
133+ fi
134+
135+ - name : Upload comparison results
136+ uses : actions/upload-artifact@v4
137+ if : always()
138+ with :
139+ name : visual-regression-comparison
140+ path : |
141+ test-results/
142+ baselines/
143+ retention-days : 14
144+
145+ - name : Comment PR with results
146+ uses : actions/github-script@v7
147+ if : always()
148+ with :
149+ script : |
150+ const fs = require('fs');
151+ const path = require('path');
152+
153+ let comment = '## 📸 Visual Regression Test Results\n\n';
154+
155+ // Check if visual tests passed
156+ if (fs.existsSync('test-results/screenshots')) {
157+ const screenshots = fs.readdirSync('test-results/screenshots');
158+ comment += `✅ Visual tests completed successfully\n`;
159+ comment += `📊 Generated ${screenshots.length} screenshot(s)\n\n`;
160+
161+ if (screenshots.length > 0) {
162+ comment += '### Screenshots Generated:\n';
163+ screenshots.forEach(screenshot => {
164+ comment += `- \`${screenshot}\`\n`;
165+ });
166+ }
167+ } else {
168+ comment += '❌ Visual tests failed to generate screenshots\n\n';
169+ }
170+
171+ comment += '\n💡 **Tip**: Download the artifacts to view the actual screenshots and compare them manually if needed.';
172+
173+ github.rest.issues.createComment({
174+ issue_number: context.issue.number,
175+ owner: context.repo.owner,
176+ repo: context.repo.repo,
177+ body: comment
178+ });
0 commit comments