Skip to content

Commit 80b9274

Browse files
feat(visual-regression): testes visuais para todos os fields
1 parent 0e75224 commit 80b9274

271 files changed

Lines changed: 3531 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,180 @@ jobs:
181181
- run: npm run build:storage:lite
182182
- run: npm run test:sync
183183
- run: npm run test:sync:schematics
184+
185+
# Detecta quais arquivos mudaram para decidir se roda testes visuais
186+
changes:
187+
name: Detect changes
188+
runs-on: ubuntu-latest
189+
if: github.event_name == 'pull_request'
190+
outputs:
191+
visual: ${{ steps.filter.outputs.visual }}
192+
steps:
193+
- uses: actions/checkout@v3
194+
- uses: dorny/paths-filter@v3
195+
id: filter
196+
with:
197+
filters: |
198+
visual:
199+
- 'e2e/visual/**'
200+
- 'projects/ui/src/lib/**'
201+
- 'package.json'
202+
- 'playwright.config.ts'
203+
- 'angular.json'
204+
- '.github/workflows/ci.yml'
205+
206+
test-visual:
207+
name: Test visual regression
208+
needs: changes
209+
# Roda sempre em push (master/development) e em PRs apenas se arquivos relevantes mudaram
210+
# Usa always() para garantir que roda em push mesmo quando o job 'changes' foi skipped
211+
if: always() && !cancelled() && (github.event_name == 'push' || needs.changes.outputs.visual == 'true')
212+
213+
runs-on: ubuntu-latest
214+
215+
steps:
216+
217+
- uses: actions/checkout@v3
218+
219+
- uses: actions/setup-node@v3
220+
with:
221+
node-version: 24
222+
223+
# Cache de node_modules para evitar npm install do zero a cada execucao
224+
- name: Cache node_modules
225+
id: cache-node-modules
226+
uses: actions/cache@v4
227+
with:
228+
path: node_modules
229+
key: node-modules-${{ runner.os }}-${{ hashFiles('package.json') }}
230+
231+
# Cache dos browsers do Playwright para evitar download a cada execucao
232+
- name: Cache Playwright browsers
233+
id: cache-playwright
234+
uses: actions/cache@v4
235+
with:
236+
path: ~/.cache/ms-playwright
237+
key: playwright-browsers-${{ runner.os }}-${{ hashFiles('package.json') }}
238+
239+
# Detecta o nome da branch atual
240+
- name: Get branch name
241+
id: branch
242+
env:
243+
HEAD_REF: ${{ github.head_ref }}
244+
REF_NAME: ${{ github.ref_name }}
245+
EVENT_NAME: ${{ github.event_name }}
246+
run: |
247+
if [ "$EVENT_NAME" = "pull_request" ]; then
248+
BRANCH_NAME="$HEAD_REF"
249+
else
250+
BRANCH_NAME="$REF_NAME"
251+
fi
252+
echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT
253+
echo "Branch name: $BRANCH_NAME"
254+
255+
# Verifica se existe uma branch de mesmo nome no po-style
256+
- name: Check for matching po-style branch
257+
id: po_style
258+
env:
259+
BRANCH_NAME: ${{ steps.branch.outputs.name }}
260+
run: |
261+
ENCODED_BRANCH=$(echo "$BRANCH_NAME" | sed 's|/|%2F|g')
262+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
263+
"https://api.github.com/repos/po-ui/po-style/branches/$ENCODED_BRANCH")
264+
if [ "$HTTP_STATUS" = "200" ]; then
265+
echo "found=true" >> $GITHUB_OUTPUT
266+
echo "Branch '$BRANCH_NAME' encontrada no po-style"
267+
else
268+
echo "found=false" >> $GITHUB_OUTPUT
269+
echo "Branch '$BRANCH_NAME' nao encontrada no po-style (HTTP $HTTP_STATUS), usando @po-ui/style do npm"
270+
fi
271+
272+
# Se encontrou a branch, clona po-style, builda e gera o tgz
273+
- name: Build po-style from matching branch
274+
if: steps.po_style.outputs.found == 'true'
275+
env:
276+
BRANCH_NAME: ${{ steps.branch.outputs.name }}
277+
run: |
278+
git clone --branch "$BRANCH_NAME" --depth 1 https://github.com/po-ui/po-style.git /tmp/po-style
279+
cd /tmp/po-style
280+
npm ci
281+
npm run build
282+
npm run pack:style
283+
echo "TGZ gerado:"
284+
ls -la dist/style/*.tgz
285+
286+
# Instala dependencias do po-angular (skip se cache hit)
287+
- name: Install dependencies
288+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
289+
run: npm i
290+
291+
# Se o cache de node_modules foi restaurado mas NAO existe branch po-style,
292+
# reinstala @po-ui/style do npm para evitar versao stale de um tgz anterior
293+
- name: Ensure clean po-style from npm
294+
if: steps.cache-node-modules.outputs.cache-hit == 'true' && steps.po_style.outputs.found != 'true'
295+
run: npm install @po-ui/style@$(node -p "require('./package.json').dependencies['@po-ui/style']")
296+
297+
# Se tiver o tgz do po-style, instala por cima da versao do npm
298+
- name: Install po-style from tgz
299+
if: steps.po_style.outputs.found == 'true'
300+
run: |
301+
TGZ_PATH=$(ls /tmp/po-style/dist/style/*.tgz)
302+
echo "Instalando @po-ui/style a partir de: $TGZ_PATH"
303+
npm install "$TGZ_PATH"
304+
305+
# Cache do build da lib UI para evitar rebuild a cada execucao
306+
- name: Cache UI build
307+
id: cache-ui-build
308+
uses: actions/cache@v4
309+
with:
310+
path: dist/ng-components
311+
key: ui-build-${{ runner.os }}-${{ hashFiles('projects/ui/src/**', 'package.json') }}
312+
313+
- name: Build UI library
314+
if: steps.cache-ui-build.outputs.cache-hit != 'true'
315+
run: npm run build:ui:lite
316+
317+
# Instala dependencias de sistema do Playwright (sempre necessario, mesmo com cache de browsers)
318+
- name: Install Playwright system deps
319+
run: npx playwright install-deps chromium
320+
321+
# Instala browsers do Playwright (skip se cache hit)
322+
- name: Install Playwright browsers
323+
if: steps.cache-playwright.outputs.cache-hit != 'true'
324+
run: npx playwright install chromium
325+
326+
# Cache de baselines geradas no ambiente CI (sem restore-keys para evitar matches parciais stale)
327+
- name: Restore visual regression baselines from cache
328+
id: baselines-cache
329+
uses: actions/cache@v4
330+
with:
331+
path: e2e/visual/__snapshots__
332+
key: visual-baselines-${{ runner.os }}-${{ hashFiles('e2e/visual/**/*.visual.spec.ts', 'e2e/visual/**/*.component.html') }}
333+
334+
# Se nao encontrou baselines no cache, regenera todas para o ambiente CI (Linux)
335+
# Usa --update-snapshots para sobrescrever baselines commitadas (geradas em outro OS)
336+
- name: Generate baselines for CI environment
337+
if: steps.baselines-cache.outputs.cache-hit != 'true'
338+
run: npx playwright test --update-snapshots --reporter=list
339+
340+
# Executa os testes visuais comparando com as baselines
341+
- name: Run visual regression tests
342+
run: npx playwright test
343+
344+
# Disponibiliza o relatorio HTML do Playwright como artefato
345+
- name: Upload visual regression report
346+
uses: actions/upload-artifact@v4
347+
if: ${{ !cancelled() }}
348+
with:
349+
name: visual-regression-report
350+
path: e2e/visual/playwright-report/
351+
retention-days: 15
352+
353+
# Disponibiliza os resultados de teste (diffs, screenshots) como artefato
354+
- name: Upload visual regression test results
355+
uses: actions/upload-artifact@v4
356+
if: ${{ !cancelled() }}
357+
with:
358+
name: visual-regression-test-results
359+
path: e2e/visual/test-results/
360+
retention-days: 15

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ testem.log
4949
.scannerwork
5050
.env
5151

52+
# Playwright
53+
/e2e/visual/test-results/
54+
/e2e/visual/playwright-report/
55+
5256
# System Files
5357
.DS_Store
5458
Thumbs.db

angular.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,46 @@
266266
}
267267
}
268268
},
269+
"visual-app": {
270+
"projectType": "application",
271+
"schematics": {},
272+
"root": "e2e/visual",
273+
"sourceRoot": "e2e/visual",
274+
"prefix": "app",
275+
"architect": {
276+
"build": {
277+
"builder": "@angular-devkit/build-angular:application",
278+
"options": {
279+
"outputPath": {
280+
"base": "dist/visual-app"
281+
},
282+
"index": "e2e/visual/app/index.html",
283+
"polyfills": ["e2e/visual/app/polyfills.ts"],
284+
"tsConfig": "e2e/visual/tsconfig.visual.json",
285+
"assets": [
286+
{
287+
"glob": "**/*",
288+
"input": "node_modules/@po-ui/style/images",
289+
"output": "/assets/images"
290+
}
291+
],
292+
"styles": ["./node_modules/@po-ui/style/css/po-theme-default.min.css"],
293+
"scripts": [],
294+
"extractLicenses": false,
295+
"sourceMap": true,
296+
"optimization": false,
297+
"namedChunks": true,
298+
"browser": "e2e/visual/app/main.ts"
299+
}
300+
},
301+
"serve": {
302+
"builder": "@angular-devkit/build-angular:dev-server",
303+
"options": {
304+
"buildTarget": "visual-app:build"
305+
}
306+
}
307+
}
308+
},
269309
"portal": {
270310
"projectType": "application",
271311
"schematics": {},

0 commit comments

Comments
 (0)