Skip to content

Commit 8f5ccef

Browse files
amanmahajan7github-actions[bot]nstepien
authored
Update Vitest (#3867)
* Vitest 4 beta * Use SHA * Set up workflow * first test * run workflow on lael * format * Tweak * manually run workflow * typo * main * Tweak * fix syntax * revert * Fix step * Update command * Do we need this command? * Revert "Do we need this command?" This reverts commit 7a66594. * Does this remove label? * set env * try `actions-ecosystem/action-remove-labels` * New approach * Does this work * Update visual regression screenshots Co-authored-by: amanmahajan7 * Does this work? * Try this * Update visual regression screenshots Co-authored-by: amanmahajan7 * Simplify * remove name * Update visual regression screenshots Co-authored-by: amanmahajan7 * Tweaks * Fix permissions * Tweak * test * Does this work? * Update screenshots Co-authored-by: amanmahajan7 * Tweaks * Tweak coverage * Tweak coverage * Does this work? * Does this work? * Does this work? * Does this work? * Fix watch * different coverage directories? * Fix typo * Another * `beta.12` * Run VRT in FF also * install ff * Update screenshots Co-authored-by: amanmahajan7 * Fix tests * update package * update test * Update screenshots Co-authored-by: amanmahajan7 * add formatter * Update screenshots Co-authored-by: amanmahajan7 * pin * Still need this :( * unpin * Update deps * Import from `vitest/browser` * update deps * Add back clsx * Fix biome/eslint * update deps * Use async render * Move async * Fix eslint * Enable tracing * Remove VRT changes * Revert .gitignore changes * Fix types * fix 2 tests * set scale * Fix tests for now * Revert commands * typo * Update tsconfig.test.json Co-authored-by: Nicolas Stepien <[email protected]> * Update package.json Co-authored-by: Nicolas Stepien <[email protected]> * Revert "Update package.json" This reverts commit 41445b1. * remove @vitest/browser --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicolas Stepien <[email protected]> Co-authored-by: Nicolas Stepien <[email protected]>
1 parent 6021e3c commit 8f5ccef

40 files changed

+360
-327
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ __screenshots__
99
npm-debug.log
1010
**.orig
1111
.idea
12+
.vitest-attachments
13+
14+
__traces__

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ function MyGrid() {
579579
return <DataGrid aria-label="my-grid" columns={columns} rows={rows} />;
580580
}
581581

582-
test('grid', () => {
583-
render(<MyGrid />);
582+
test('grid', async () => {
583+
await render(<MyGrid />);
584584
const grid = screen.getByRole('grid', { name: 'my-grid' });
585585
});
586586
```

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
"@typescript-eslint/eslint-plugin": "^8.39.1",
6565
"@typescript-eslint/parser": "^8.39.1",
6666
"@vitejs/plugin-react": "5.0.2",
67-
"@vitest/browser": "^3.2.4",
68-
"@vitest/coverage-istanbul": "^3.2.4",
67+
"@vitest/browser-playwright": "^4.0.1",
68+
"@vitest/coverage-istanbul": "^4.0.1",
6969
"@vitest/eslint-plugin": "^1.3.4",
7070
"@wyw-in-js/rollup": "^0.7.0",
7171
"@wyw-in-js/vite": "^0.7.0",
@@ -78,7 +78,7 @@
7878
"eslint-plugin-testing-library": "^7.10.0",
7979
"jspdf": "^3.0.1",
8080
"jspdf-autotable": "^5.0.2",
81-
"playwright": "^1.54.2",
81+
"playwright": "^1.56.1",
8282
"postcss": "^8.5.2",
8383
"prettier": "3.6.2",
8484
"react": "^19.2.0",
@@ -87,8 +87,8 @@
8787
"rolldown-plugin-dts": "^0.16.1",
8888
"typescript": "~5.9.2",
8989
"vite": "npm:rolldown-vite@^7.1.3",
90-
"vitest": "^3.2.4",
91-
"vitest-browser-react": "^1.0.1"
90+
"vitest": "^4.0.1",
91+
"vitest-browser-react": "^2.0.0"
9292
},
9393
"peerDependencies": {
9494
"react": "^19.2",

test/browser/TextEditor.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react';
2-
import { page, userEvent } from '@vitest/browser/context';
2+
import { page, userEvent } from 'vitest/browser';
33

44
import { DataGrid, textEditor } from '../../src';
55
import type { Column } from '../../src';
@@ -27,7 +27,7 @@ function Test() {
2727
}
2828

2929
test('TextEditor', async () => {
30-
page.render(<Test />);
30+
await page.render(<Test />);
3131
const cell = page.getByRole('gridcell');
3232
await expect.element(cell).toHaveTextContent(/^Tacitus Kilgore$/);
3333
await userEvent.dblClick(cell);

test/browser/TreeDataGrid.test.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react';
2-
import { page, userEvent } from '@vitest/browser/context';
2+
import { page, userEvent } from 'vitest/browser';
33

44
import type { Column } from '../../src';
55
import { SelectColumn, textEditor, TreeDataGrid } from '../../src';
@@ -136,7 +136,7 @@ function rowGrouper(rows: readonly Row[], columnKey: string) {
136136
}
137137

138138
function setup(groupBy: string[], groupIdGetter?: (groupKey: string, parentId?: string) => string) {
139-
page.render(<TestGrid groupBy={groupBy} groupIdGetter={groupIdGetter} />);
139+
return page.render(<TestGrid groupBy={groupBy} groupIdGetter={groupIdGetter} />);
140140
}
141141

142142
async function testHeaderCellsContent(expected: readonly string[]) {
@@ -147,27 +147,27 @@ async function testHeaderCellsContent(expected: readonly string[]) {
147147
}
148148

149149
test('should not group if groupBy is empty', async () => {
150-
setup([]);
150+
await setup([]);
151151
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '7');
152152
await testHeaderCellsContent(['', 'Sport', 'Country', 'Year', 'Id']);
153153
await testRowCount(7);
154154
});
155155

156156
test('should not group if column does not exist', async () => {
157-
setup(['abc']);
157+
await setup(['abc']);
158158
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '7');
159159
await testRowCount(7);
160160
});
161161

162162
test('should group by single column', async () => {
163-
setup(['country']);
163+
await setup(['country']);
164164
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '9');
165165
await testHeaderCellsContent(['', 'Country', 'Sport', 'Year', 'Id']);
166166
await testRowCount(5);
167167
});
168168

169169
test('should group by multiple columns', async () => {
170-
setup(['country', 'year']);
170+
await setup(['country', 'year']);
171171
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '13');
172172
await testHeaderCellsContent(['', 'Country', 'Year', 'Sport', 'Id']);
173173
await testRowCount(5);
@@ -177,7 +177,7 @@ test('should use groupIdGetter when provided', async () => {
177177
const groupIdGetter = vi.fn((groupKey: string, parentId?: string) =>
178178
parentId !== undefined ? `${groupKey}#${parentId}` : groupKey
179179
);
180-
setup(['country', 'year'], groupIdGetter);
180+
await setup(['country', 'year'], groupIdGetter);
181181
expect(groupIdGetter).toHaveBeenCalled();
182182
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '13');
183183
await testHeaderCellsContent(['', 'Country', 'Year', 'Sport', 'Id']);
@@ -193,20 +193,20 @@ test('should use groupIdGetter when provided', async () => {
193193
});
194194

195195
test('should ignore duplicate groupBy columns', async () => {
196-
setup(['year', 'year', 'year']);
196+
await setup(['year', 'year', 'year']);
197197
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '10');
198198
await testRowCount(6);
199199
});
200200

201201
test('should use groupBy order while grouping', async () => {
202-
setup(['year', 'country']);
202+
await setup(['year', 'country']);
203203
await expect.element(getTreeGrid()).toHaveAttribute('aria-rowcount', '14');
204204
await testHeaderCellsContent(['', 'Year', 'Country', 'Sport', 'Id']);
205205
await testRowCount(6);
206206
});
207207

208208
test('should toggle group when group cell is clicked', async () => {
209-
setup(['year']);
209+
await setup(['year']);
210210
await testRowCount(6);
211211
const groupCell = getCell('2021');
212212
await userEvent.click(groupCell);
@@ -216,7 +216,7 @@ test('should toggle group when group cell is clicked', async () => {
216216
});
217217

218218
test('should toggle group using keyboard', async () => {
219-
setup(['year']);
219+
await setup(['year']);
220220
await testRowCount(6);
221221
const groupCell = getCell('2021');
222222
await userEvent.click(groupCell);
@@ -231,7 +231,7 @@ test('should toggle group using keyboard', async () => {
231231
});
232232

233233
test('should set aria-attributes', async () => {
234-
setup(['year', 'country']);
234+
await setup(['year', 'country']);
235235

236236
const groupRow1 = getRowByCellName('2020');
237237
await expect.element(groupRow1).toHaveAttribute('aria-level', '1');
@@ -264,7 +264,7 @@ test('should set aria-attributes', async () => {
264264
});
265265

266266
test('should select rows in a group', async () => {
267-
setup(['year', 'country']);
267+
await setup(['year', 'country']);
268268

269269
const headerCheckbox = getSelectAllCheckbox();
270270
await expect.element(headerCheckbox).not.toBeChecked();
@@ -316,7 +316,7 @@ test('should select rows in a group', async () => {
316316
});
317317

318318
test('cell navigation in a treegrid', async () => {
319-
setup(['country', 'year']);
319+
await setup(['country', 'year']);
320320
await testRowCount(5);
321321
const focusSink = page.getBySelector(`.${focusSinkClassname}`);
322322

@@ -399,7 +399,7 @@ test('cell navigation in a treegrid', async () => {
399399
});
400400

401401
test('copy/paste when grouping is enabled', async () => {
402-
setup(['year']);
402+
await setup(['year']);
403403
await userEvent.click(getCell('2021'));
404404
await userEvent.copy();
405405
expect(onCellCopySpy).not.toHaveBeenCalled();
@@ -434,7 +434,7 @@ test('copy/paste when grouping is enabled', async () => {
434434
});
435435

436436
test('update row using cell renderer', async () => {
437-
setup(['year']);
437+
await setup(['year']);
438438
await userEvent.click(getCell('2021'));
439439
await userEvent.click(getCell('USA'));
440440
await userEvent.keyboard('{arrowright}{arrowright}');
@@ -444,7 +444,7 @@ test('update row using cell renderer', async () => {
444444
});
445445

446446
test('custom renderGroupCell', async () => {
447-
setup(['country']);
447+
await setup(['country']);
448448
await expect.element(getRowByCellName('USA').getByRole('gridcell').nth(4)).toHaveTextContent('1');
449449
await expect
450450
.element(getRowByCellName('Canada').getByRole('gridcell').nth(4))

test/browser/column/cellClass.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('cellClass is undefined', async () => {
1515
name: 'ID'
1616
}
1717
];
18-
setup({ columns, rows });
18+
await setup({ columns, rows });
1919
const [cell1, cell2] = getCellsNew('0', '1');
2020
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
2121
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });
@@ -29,7 +29,7 @@ test('cellClass is a string', async () => {
2929
cellClass: 'my-cell'
3030
}
3131
];
32-
setup({ columns, rows });
32+
await setup({ columns, rows });
3333
const [cell1, cell2] = getCellsNew('0', '1');
3434
await expect.element(cell1).toHaveClass(`${cellClassname} my-cell`, { exact: true });
3535
await expect.element(cell2).toHaveClass(`${cellClassname} my-cell`, { exact: true });
@@ -43,7 +43,7 @@ test('cellClass returns a string', async () => {
4343
cellClass: (row) => `my-cell-${row.id}`
4444
}
4545
];
46-
setup({ columns, rows });
46+
await setup({ columns, rows });
4747
const [cell1, cell2] = getCellsNew('0', '1');
4848
await expect.element(cell1).toHaveClass(`${cellClassname} my-cell-0`, { exact: true });
4949
await expect.element(cell2).toHaveClass(`${cellClassname} my-cell-1`, { exact: true });
@@ -57,7 +57,7 @@ test('cellClass returns undefined', async () => {
5757
cellClass: () => undefined
5858
}
5959
];
60-
setup({ columns, rows });
60+
await setup({ columns, rows });
6161
const [cell1, cell2] = getCellsNew('0', '1');
6262
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
6363
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });

test/browser/column/colSpan.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { userEvent } from '@vitest/browser/context';
1+
import { userEvent } from 'vitest/browser';
22

33
import type { Column } from '../../../src';
44
import { getCellsAtRowIndex, getHeaderCells, setup, validateCellPosition } from '../utils';
55

66
describe('colSpan', () => {
7-
function setupColSpanGrid(colCount = 15) {
7+
function setupColSpan(colCount = 15) {
88
type Row = number;
99
const columns: Column<Row, Row>[] = [];
1010
const rows: readonly Row[] = Array.from({ length: 10 }, (_, i) => i);
@@ -34,11 +34,11 @@ describe('colSpan', () => {
3434
}
3535
});
3636
}
37-
setup({ columns, rows, bottomSummaryRows: [1, 2], topSummaryRows: [1, 2] });
37+
return setup({ columns, rows, bottomSummaryRows: [1, 2], topSummaryRows: [1, 2] });
3838
}
3939

40-
it('should merges cells', () => {
41-
setupColSpanGrid();
40+
it('should merges cells', async () => {
41+
await setupColSpan();
4242
// header
4343
expect(getHeaderCells()).toHaveLength(13);
4444

@@ -93,7 +93,7 @@ describe('colSpan', () => {
9393
});
9494

9595
it('should navigate between merged cells', async () => {
96-
setupColSpanGrid();
96+
await setupColSpan();
9797
// header row
9898
await userEvent.click(getHeaderCells()[7]);
9999
await validateCellPosition(7, 0);
@@ -171,7 +171,7 @@ describe('colSpan', () => {
171171
});
172172

173173
it('should scroll to the merged cell when selected', async () => {
174-
setupColSpanGrid(30);
174+
await setupColSpan(30);
175175
await userEvent.click(getCellsAtRowIndex(10)[23]); // last visible cell (1920/80)
176176
const spy = vi.spyOn(window.HTMLElement.prototype, 'scrollIntoView');
177177
const testScrollIntoView = () => {

test/browser/column/draggable.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { userEvent } from '@vitest/browser/context';
1+
import { userEvent } from 'vitest/browser';
22

33
import type { Column } from '../../../src';
44
import { getHeaderCellsNew, setup } from '../utils';
@@ -27,7 +27,7 @@ const columns: readonly Column<never>[] = [
2727

2828
test('draggable columns', async () => {
2929
const onColumnsReorder = vi.fn();
30-
setup({ columns, rows: [], onColumnsReorder });
30+
await setup({ columns, rows: [], onColumnsReorder });
3131
const [cell1, cell2, cell3, cell4] = getHeaderCellsNew('col1', 'col2', 'col3', 'col4');
3232

3333
await expect.element(cell1).not.toHaveAttribute('draggable');

test/browser/column/frozen.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { page } from '@vitest/browser/context';
1+
import { page } from 'vitest/browser';
22

33
import type { Column } from '../../../src';
44
import { cellClassname, cellFrozenClassname } from '../../../src/style/cell';
@@ -27,7 +27,7 @@ test('frozen column have a specific class, and are stable-sorted before non-froz
2727
}
2828
];
2929

30-
setup({ columns, rows: [] });
30+
await setup({ columns, rows: [] });
3131
await expect.element(page.getByRole('row')).toHaveTextContent('col1col3col2col4');
3232
const [cell1, cell2, cell3, cell4] = getHeaderCellsNew('col1', 'col2', 'col3', 'col4');
3333

test/browser/column/grouping.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { page, userEvent } from '@vitest/browser/context';
1+
import { page, userEvent } from 'vitest/browser';
22

33
import type { ColumnOrColumnGroup } from '../../../src';
44
import {
@@ -95,7 +95,7 @@ const columns: readonly ColumnOrColumnGroup<NonNullable<unknown>>[] = [
9595
];
9696

9797
test('grouping', async () => {
98-
setup({ columns, rows: [{}] });
98+
await setup({ columns, rows: [{}] });
9999

100100
const grid = getGrid();
101101
await expect.element(grid).toHaveAttribute('aria-colcount', '12');
@@ -253,7 +253,7 @@ test('grouping', async () => {
253253
});
254254

255255
test('keyboard navigation', async () => {
256-
setup({ columns, rows: [{}] }, true);
256+
await setup({ columns, rows: [{}] }, true);
257257

258258
// no initial selection
259259
await expect.element(getSelectedCell()).not.toBeInTheDocument();

0 commit comments

Comments
 (0)