Skip to content

Commit 9189d89

Browse files
committed
Initial commit
1 parent 6021e3c commit 9189d89

File tree

6 files changed

+154
-5
lines changed

6 files changed

+154
-5
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
node-version: 25
1616
check-latest: true
17-
- name: npm install
17+
- name: Install dependencies
1818
run: npm i
1919
- name: Biome
2020
run: node --run biome:ci
@@ -32,7 +32,9 @@ jobs:
3232
run: npx playwright install chromium firefox
3333
- name: Test
3434
run: node --run test
35-
timeout-minutes: 4
35+
timeout-minutes: 4timeout-minutes: 4
36+
- name: Visual regression test
37+
run: node --run visual
3638
- name: Upload coverage
3739
uses: codecov/codecov-action@v5
3840
with:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Update Screenshots
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
7+
env:
8+
AUTHOR_NAME: 'github-actions[bot]'
9+
AUTHOR_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
10+
COMMIT_MESSAGE: |
11+
Update screenshots
12+
13+
Co-authored-by: ${{ github.actor }}
14+
15+
jobs:
16+
update-screenshots:
17+
if: ${{ github.event.label.name == 'Update Screenshots' }}
18+
runs-on: ubuntu-latest
19+
20+
permissions:
21+
contents: write
22+
pull-requests: write
23+
24+
# one at a time per branch
25+
concurrency:
26+
group: update-screenshots@${{ github.head_ref }}
27+
cancel-in-progress: true
28+
29+
steps:
30+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
31+
with:
32+
ref: ${{ github.head_ref }}
33+
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444
34+
with:
35+
node-version: 24
36+
check-latest: true
37+
- name: Remove label
38+
uses: actions-ecosystem/action-remove-labels@2ce5d41b4b6aa8503e285553f75ed56e0a40bae0
39+
with:
40+
labels: 'Update Screenshots'
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
- name: Install dependencies
43+
run: npm i
44+
- name: Install Playwright Browsers
45+
run: npx playwright install chromium firefox
46+
- name: Update screenshots
47+
run: node --run visual:update
48+
- name: Push new screenshots
49+
run: |
50+
git config --global user.name "${{ env.AUTHOR_NAME }}"
51+
git config --global user.email "${{ env.AUTHOR_EMAIL }}"
52+
git add visual/__screenshots__/.
53+
git diff-index --quiet HEAD || git commit -m "${{ env.COMMIT_MESSAGE }}"
54+
git push --set-upstream origin ${{ github.head_ref }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
/lib
55
/node_modules
66
/package-lock.json
7-
__screenshots__
7+
test/**/__screenshots__
88

99
npm-debug.log
1010
**.orig
1111
.idea
12+
.vitest-attachments

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
"preview": "vite preview",
3636
"build:website": "vite build",
3737
"build": "rolldown -c",
38-
"test": "vitest run",
39-
"test:watch": "vitest watch",
38+
"test": "vitest run --project browser --project node --coverage.reportsDirectory='./coverage/test'",
39+
"test:watch": "vitest watch --project browser --project node",
40+
"visual": "vitest run --project visual --coverage.reportsDirectory='./coverage/visual'",
41+
"visual:update": "vitest run --project visual --update",
4042
"format": "biome format --write",
4143
"check": "biome check --error-on-warnings",
4244
"biome:ci": "biome ci --error-on-warnings",

visual/basicGrid.test.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { page } from 'vitest/browser';
2+
3+
import { DataGrid, SelectColumn, type Column } from '../src';
4+
import { getGrid } from '../test/browser/utils';
5+
6+
interface Row {
7+
id: number;
8+
name: string;
9+
}
10+
11+
const columns: readonly Column<Row, Row>[] = [
12+
SelectColumn,
13+
{
14+
key: 'name',
15+
name: 'Name',
16+
renderSummaryCell(props) {
17+
return props.row.name;
18+
}
19+
}
20+
];
21+
22+
const rows: readonly Row[] = [
23+
{ id: 1, name: 'Row 1' },
24+
{ id: 2, name: 'Row 2' },
25+
{ id: 3, name: 'Row 3' }
26+
];
27+
28+
const topSummaryRows: readonly Row[] = [
29+
{ id: 4, name: 'Top Summary Row 1' },
30+
{ id: 5, name: 'Top Summary Row 2' }
31+
];
32+
33+
const bottomSummaryRows: readonly Row[] = [
34+
{ id: 4, name: 'Top Summary Row 1' },
35+
{ id: 5, name: 'Top Summary Row 2' }
36+
];
37+
38+
function rowKeyGetter(row: Row) {
39+
return row.id;
40+
}
41+
42+
test('basic grid', async () => {
43+
page.render(
44+
<DataGrid
45+
rowKeyGetter={rowKeyGetter}
46+
columns={columns}
47+
rows={rows}
48+
topSummaryRows={topSummaryRows}
49+
bottomSummaryRows={bottomSummaryRows}
50+
/>
51+
);
52+
53+
await expect(getGrid()).toMatchScreenshot('basic-grid');
54+
});

vite.config.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,42 @@ export default defineConfig(({ command, isPreview }) => ({
138138
setupFiles: ['test/setupBrowser.ts']
139139
}
140140
},
141+
{
142+
extends: true,
143+
test: {
144+
name: 'visual',
145+
include: ['visual/*.test.*'],
146+
browser: {
147+
enabled: true,
148+
provider: playwright(),
149+
instances: [
150+
{
151+
browser: 'chromium',
152+
context: { viewport }
153+
},
154+
{
155+
browser: 'firefox',
156+
context: { viewport }
157+
}
158+
],
159+
viewport,
160+
headless: true,
161+
screenshotFailures: false
162+
},
163+
setupFiles: ['test/setupBrowser.ts']
164+
},
165+
toMatchScreenshot: {
166+
comparatorName: 'pixelmatch',
167+
comparatorOptions: {
168+
// TODO: finalize these values
169+
// 0-1, how different can colors be?
170+
threshold: 0.2,
171+
// 1% of pixels can differ
172+
allowedMismatchedPixelRatio: 0.01
173+
}
174+
},
175+
setupFiles: ['test/setupBrowser.ts']
176+
},
141177
{
142178
extends: true,
143179
test: {

0 commit comments

Comments
 (0)