Skip to content

Commit f453093

Browse files
authored
feat: add visual regression tests
* feat: initial test setup * chore: adding more snapshot tests to palywright * chore: update README.md * chore: update vitest config to exlude playwright tests * chore: update tests * refactor: remove waits from tests * chore: fix few tests; add tests to workflow * chore: build locally tests in dockerfile * fix: revert changes that was testing for visual regression * fix: remove some not used parts of docker-compose.yaml * ci: reuse comment instead of creating a new one * fix: gha comment * fix: improve the comment body * refactor: rename dockerfile * fix: minor improvments
1 parent 7845dde commit f453093

File tree

70 files changed

+793
-20
lines changed

Some content is hidden

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

70 files changed

+793
-20
lines changed

.dockerignore

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Node.js dependencies
2+
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Build outputs
8+
dist
9+
build
10+
.next
11+
out
12+
13+
# Test artifacts
14+
test-results
15+
playwright-report
16+
coverage
17+
*.lcov
18+
19+
# Environment files
20+
.env
21+
.env.local
22+
.env.development.local
23+
.env.test.local
24+
.env.production.local
25+
26+
# IDE files
27+
.vscode
28+
.idea
29+
*.swp
30+
*.swo
31+
*~
32+
33+
# OS generated files
34+
.DS_Store
35+
.DS_Store?
36+
._*
37+
.Spotlight-V100
38+
.Trashes
39+
ehthumbs.db
40+
Thumbs.db
41+
42+
# Docker files - prevent these from being included in the image context
43+
Dockerfile*
44+
docker-compose*
45+
.dockerignore
46+
47+
# CI/CD
48+
.github
49+
.husky
50+
51+
# Temporary files
52+
tmp
53+
temp
54+
*.tmp
55+
*.temp
56+
57+
# Log files
58+
logs
59+
*.log
60+
61+
# Cache directories
62+
.cache
63+
.parcel-cache
64+
.eslintcache
65+
66+
# Runtime data
67+
pids
68+
*.pid
69+
*.seed
70+
*.pid.lock
71+
72+
# Optional npm cache directory
73+
.npm
74+
75+
# Optional REPL history
76+
.node_repl_history
77+
78+
# Output of 'npm pack'
79+
*.tgz
80+
81+
# Yarn Integrity file
82+
.yarn-integrity

.github/workflows/node.js.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches: ["main"]
99
pull_request:
10-
branches: [ "main" ]
11-
10+
branches: ["main"]
1211

1312
jobs:
1413
build:
15-
1614
runs-on: ubuntu-latest
1715

1816
steps:
19-
- uses: actions/checkout@v4
20-
with:
21-
submodules: 'true'
22-
- name: Use Node.js
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version: 22
26-
cache: "npm"
27-
- run: npm ci
28-
- run: npm run qa
29-
- run: npm run build --if-present
30-
- run: npm test
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: "true"
20+
- name: Use Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22
24+
cache: "npm"
25+
- run: npm ci
26+
- run: npm run qa
27+
- run: npm run build --if-present
28+
- run: npm test
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Visual Regression Tests
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
10+
jobs:
11+
visual-tests:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: "true"
21+
22+
- name: Build Docker image
23+
run: docker build -f Dockerfile.snapshot-tests -t playwright-test .
24+
25+
- name: Run visual regression tests
26+
run: |
27+
docker run --rm \
28+
-v ${{ github.workspace }}/tools/snapshot-tests/test-results:/app/tools/snapshot-tests/test-results \
29+
-v ${{ github.workspace }}/tools/snapshot-tests/playwright-report:/app/tools/snapshot-tests/playwright-report \
30+
-e CI=true \
31+
playwright-test \
32+
sh -c "cd tools/snapshot-tests && npm run test"
33+
34+
- name: Upload Playwright Report
35+
uses: actions/upload-artifact@v4
36+
if: ${{ always() && hashFiles('tools/snapshot-tests/playwright-report/**') != '' }}
37+
with:
38+
name: playwright-report-${{ github.run_number }}
39+
path: tools/snapshot-tests/playwright-report/
40+
retention-days: 30
41+
42+
- name: Comment PR with Visual Test Report
43+
uses: actions/github-script@v7
44+
if: ${{ always() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
45+
with:
46+
script: |
47+
const testStatus = '${{ job.status }}' === 'success' ? '✅ Passed' : '❌ Failed';
48+
49+
const body = `## Visual Regression Test Report ${testStatus}
50+
51+
Github run id: ${{github.run_id}}
52+
53+
🔗 **Artifacts**: [Download](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
54+
`
55+
56+
const comments = await github.rest.issues.listComments({
57+
issue_number: context.issue.number,
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
});
61+
62+
const botComment = comments.data.find(comment =>
63+
comment.user.login === 'github-actions[bot]' &&
64+
comment.body.includes('Visual Regression Test Report')
65+
);
66+
67+
if (botComment) {
68+
await github.rest.issues.updateComment({
69+
comment_id: botComment.id,
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
body: body
73+
});
74+
} else {
75+
await github.rest.issues.createComment({
76+
issue_number: context.issue.number,
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
body: body
80+
});
81+
}

Dockerfile.snapshot-tests

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
FROM mcr.microsoft.com/playwright:v1.55.1-noble AS base
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
git \
5+
curl \
6+
&& rm -rf /var/lib/apt/lists/* \
7+
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
8+
&& apt-get install -y nodejs \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /app
12+
13+
# ============================================
14+
# Stage 1: Main Dependencies
15+
# This stage only rebuilds when main package.json files change
16+
# ============================================
17+
FROM base AS main-dependencies
18+
19+
COPY package*.json ./
20+
COPY shared/links-metadata/package*.json ./shared/links-metadata/
21+
22+
RUN npm ci
23+
24+
# ============================================
25+
# Stage 2: Test Dependencies
26+
# This stage only rebuilds when test package.json files change
27+
# ============================================
28+
FROM base AS test-dependencies
29+
30+
COPY tools/snapshot-tests/package*.json ./tools/snapshot-tests/
31+
32+
RUN cd tools/snapshot-tests && npm install
33+
34+
RUN cd tools/snapshot-tests && npx playwright install chromium
35+
36+
# ============================================
37+
# Stage 3: Source and Build
38+
# This stage handles source code and building
39+
# ============================================
40+
FROM main-dependencies AS builder
41+
42+
COPY .git ./.git
43+
COPY .gitmodules ./
44+
45+
COPY scripts ./scripts/
46+
47+
COPY shared/links-metadata ./shared/links-metadata/
48+
49+
RUN cd shared/links-metadata
50+
51+
COPY tsconfig*.json ./
52+
COPY vite.config.ts ./
53+
COPY vitest.config.ts ./
54+
COPY tailwind.config.js ./
55+
COPY biome.jsonc ./
56+
COPY index.html ./
57+
58+
COPY public ./public/
59+
COPY src ./src/
60+
61+
RUN npm run build
62+
63+
# ============================================
64+
# Stage 4: Test Runner
65+
# Final stage for running tests
66+
# ============================================
67+
FROM test-dependencies AS test-runner
68+
69+
COPY --from=builder /app/dist ./dist
70+
COPY --from=builder /app/node_modules ./node_modules
71+
COPY --from=builder /app/package.json ./package.json
72+
COPY --from=test-dependencies /app/tools/snapshot-tests/node_modules ./tools/snapshot-tests/
73+
COPY --from=test-dependencies /app/tools/snapshot-tests/package*.json ./tools/snapshot-tests/
74+
COPY tools/snapshot-tests/tests ./tools/snapshot-tests/tests
75+
COPY tools/snapshot-tests/playwright.config.ts ./tools/snapshot-tests/
76+
77+
ENV PLAYWRIGHT_START_SERVER=true
78+
ENV PLAYWRIGHT_PORT=5173
79+
ENV PLAYWRIGHT_HOST=localhost
80+
ENV CI=true
81+
82+
EXPOSE 5173
83+
84+
CMD ["/bin/sh", "-lc", "cd tools/snapshot-tests && npm run test:with-server"]
85+
86+
# ============================================
87+
# Stage 5: Development (Optional)
88+
# Use this stage for interactive development/debugging
89+
# Build with: docker build --target development -f Dockerfile.playwright -t playwright-dev .
90+
# Run with: docker run -it playwright-dev bash
91+
# ============================================
92+
FROM test-runner AS development
93+
94+
# Install additional dev tools if needed
95+
RUN apt-get update && apt-get install -y --no-install-recommends \
96+
vim \
97+
less \
98+
&& rm -rf /var/lib/apt/lists/*
99+
100+
CMD ["/bin/bash"]

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,41 @@ $ npm ci # install dependencies
3333
$ npm run dev # run the development version
3434
```
3535

36+
# Running e2e (snapshots) tests locally
3637

38+
Visual snapshot tests checks for visual regression.
3739

40+
## Docker-based Testing (Recommended)
41+
42+
For consistent snapshots that match GitHub Actions:
43+
44+
```bash
45+
# Build Docker images
46+
npm run docker:build
47+
48+
# Run tests
49+
npm run docker:test
50+
# Then open tools/snapshot-test/playwright-report/index.html for visual regression report
51+
52+
# Update snapshots
53+
npm run docker:test:update
54+
55+
```
56+
57+
## Local Testing
58+
59+
To run all visual snapshots tests locally:
60+
61+
```bash
62+
cd tools/snapshot-tests
63+
npm install
64+
npm run test
65+
```
66+
67+
One can also run tests with UI simply via:
68+
69+
```bash
70+
npm start
71+
```
72+
73+
**Note**: Local testing may produce different snapshots than CI due to environment differences. Use Docker-based testing for consistent results.

docker-compose.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
services:
2+
snapshot-tests:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile.snapshot-tests
6+
volumes:
7+
- ./tools/snapshot-tests/test-results:/app/tools/snapshot-tests/test-results
8+
- ./tools/snapshot-tests/playwright-report:/app/tools/snapshot-tests/playwright-report
9+
environment:
10+
- PLAYWRIGHT_START_SERVER=true
11+
- PLAYWRIGHT_PORT=5173
12+
- PLAYWRIGHT_HOST=localhost
13+
- CI=true
14+
- DISPLAY=:99
15+
working_dir: /app/tools/snapshot-tests
16+
command: ["npm", "run", "test"]
17+
networks:
18+
- playwright-network
19+
20+
snapshot-tests-update:
21+
build:
22+
context: .
23+
dockerfile: Dockerfile.snapshot-tests
24+
volumes:
25+
- ./tools/snapshot-tests/test-results:/app/tools/snapshot-tests/test-results
26+
- ./tools/snapshot-tests/playwright-report:/app/tools/snapshot-tests/playwright-report
27+
environment:
28+
- PLAYWRIGHT_START_SERVER=true
29+
- PLAYWRIGHT_PORT=5173
30+
- PLAYWRIGHT_HOST=localhost
31+
- CI=true
32+
- DISPLAY=:99
33+
working_dir: /app/tools/snapshot-tests
34+
command: "npm run test:update"
35+
networks:
36+
- playwright-network
37+
38+
networks:
39+
playwright-network:
40+
driver: bridge

0 commit comments

Comments
 (0)