Skip to content

Commit 3849e73

Browse files
committed
test: add visual regression testing for SVG generators
1 parent 24ce401 commit 3849e73

26 files changed

Lines changed: 403 additions & 2 deletions

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ jobs:
4747
- name: Run Unit Tests (Vitest)
4848
run: npm run test:coverage
4949

50+
- name: Upload Visual Regression Diffs
51+
if: failure()
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: visual-test-diffs
55+
path: tests/visual/diffs/
56+
if-no-files-found: ignore
57+
5058
build:
5159
name: Production Build
5260
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# testing
1414
/coverage
15+
/tests/visual/diffs/
1516

1617
# next.js
1718
/.next/

lib/svg/generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ export function generateVersusSVG(
24882488
24892489
<g transform="translate(${singleW}, ${H / 2})">
24902490
<circle cx="0" cy="0" r="${s(24)}" fill="${bg}" stroke="${accent}" stroke-width="2" />
2491-
<text x="0" y="${s(6)}" text-anchor="middle" font-family="${statsFont}" fill="${accent}" font-size="${s(16)}" font-weight="bold">VS</text>
2491+
<text x="0" y="${s(6)}" text-anchor="middle" font-family="${statsFont.replace(/"/g, "'")}" fill="${accent}" font-size="${s(16)}" font-weight="bold">VS</text>
24922492
</g>
24932493
</svg>`;
24942494
}
@@ -2595,7 +2595,7 @@ function generateAutoThemeVersusSVG(
25952595
25962596
<g transform="translate(${singleW}, ${H / 2})">
25972597
<circle cx="0" cy="0" r="${s(24)}" class="cp-bg-fill" stroke="var(--cp-accent)" stroke-width="2" />
2598-
<text x="0" y="${s(6)}" text-anchor="middle" font-family="${statsFont}" class="cp-accent-fill" font-size="${s(16)}" font-weight="bold">VS</text>
2598+
<text x="0" y="${s(6)}" text-anchor="middle" font-family="${statsFont.replace(/"/g, "'")}" class="cp-accent-fill" font-size="${s(16)}" font-weight="bold">VS</text>
25992599
</g>
26002600
</svg>`;
26012601
}

package-lock.json

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"test": "vitest run",
1515
"test:ui": "vitest --ui",
1616
"test:coverage": "vitest --coverage",
17+
"test:visual": "vitest run tests/visual",
18+
"test:visual:update": "cross-env UPDATE_VISUAL_BASELINES=true vitest run tests/visual",
1719
"bench:svg": "tsx scripts/benchmark-svg.ts",
1820
"check:api-breaking": "tsx scripts/detect-breaking-api-changes.ts",
1921
"prepare": "husky"
@@ -72,19 +74,24 @@
7274
"@types/jspdf": "^1.3.3",
7375
"@types/node": "^20",
7476
"@types/pdf-parse": "^1.1.5",
77+
"@types/pixelmatch": "^5.2.6",
78+
"@types/pngjs": "^6.0.5",
7579
"@types/react": "^19",
7680
"@types/react-dom": "^19",
7781
"@vitejs/plugin-react": "^6.0.2",
7882
"@vitest/coverage-v8": "^4.1.4",
7983
"@vitest/ui": "^4.1.4",
8084
"autoprefixer": "^10.5.0",
85+
"cross-env": "^10.1.0",
8186
"eslint": "^9",
8287
"eslint-config-next": "16.2.3",
8388
"eslint-config-prettier": "^10.1.8",
8489
"husky": "^9.1.7",
8590
"jsdom": "^29.1.1",
8691
"lint-staged": "^15.2.11",
8792
"node-mocks-http": "^1.17.2",
93+
"pixelmatch": "^7.2.0",
94+
"pngjs": "^7.0.0",
8895
"postcss": "^8.5.10",
8996
"prettier": "^3.8.3",
9097
"react-is": "^19.2.6",
50.4 KB
Loading
1.57 KB
Loading
18.9 KB
Loading
41 KB
Loading
4.58 KB
Loading

0 commit comments

Comments
 (0)