Skip to content

Commit 75fc5f3

Browse files
authored
Set up vitest workspaces, re-enable ssr test (adazzle#3592)
1 parent 25d0617 commit 75fc5f3

34 files changed

+107
-88
lines changed

test/TextEditor.test.tsx renamed to test/browser/TextEditor.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState } from 'react';
22
import { fireEvent, render, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid, { textEditor } from '../src';
6-
import type { Column } from '../src';
5+
import DataGrid, { textEditor } from '../../src';
6+
import type { Column } from '../../src';
77
import { getCells } from './utils';
88

99
interface Row {

test/TreeDataGrid.test.tsx renamed to test/browser/TreeDataGrid.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { useState } from 'react';
22
import { render, screen, within } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import type { Column } from '../src';
6-
import { SelectColumn, textEditor, TreeDataGrid } from '../src';
7-
import { focusSinkClassname } from '../src/style/core';
8-
import { rowSelected } from '../src/style/row';
9-
import type { PasteEvent } from '../src/types';
5+
import type { Column } from '../../src';
6+
import { SelectColumn, textEditor, TreeDataGrid } from '../../src';
7+
import { focusSinkClassname } from '../../src/style/core';
8+
import { rowSelected } from '../../src/style/row';
9+
import type { PasteEvent } from '../../src/types';
1010
import {
1111
copySelectedCell,
1212
getCellsAtRowIndex,

test/column/cellClass.test.ts renamed to test/browser/column/cellClass.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Column } from '../../src';
2-
import { cellClassname } from '../../src/style/cell';
1+
import type { Column } from '../../../src';
2+
import { cellClassname } from '../../../src/style/cell';
33
import { getCells, setup } from '../utils';
44

55
interface Row {

test/column/colSpan.test.ts renamed to test/browser/column/colSpan.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import userEvent from '@testing-library/user-event';
22

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

66
describe('colSpan', () => {

test/column/draggable.test.ts renamed to test/browser/column/draggable.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { act } from 'react';
22
import { userEvent } from '@vitest/browser/context';
33

4-
import type { Column } from '../../src';
4+
import type { Column } from '../../../src';
55
import { getHeaderCells, setup } from '../utils';
66

77
const columns: readonly Column<never>[] = [

test/column/frozen.test.ts renamed to test/browser/column/frozen.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Column } from '../../src';
2-
import { cellClassname, cellFrozenClassname } from '../../src/style/cell';
1+
import type { Column } from '../../../src';
2+
import { cellClassname, cellFrozenClassname } from '../../../src/style/cell';
33
import { getHeaderCells, setup } from '../utils';
44

55
test('frozen column have a specific class, and are stable-sorted before non-frozen columns', () => {

test/column/grouping.test.ts renamed to test/browser/column/grouping.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { screen, within } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

4-
import type { ColumnOrColumnGroup } from '../../src';
4+
import type { ColumnOrColumnGroup } from '../../../src';
55
import { getSelectedCell, setup, validateCellPosition } from '../utils';
66

77
const columns: readonly ColumnOrColumnGroup<NonNullable<unknown>>[] = [

test/column/headerCellClass.test.ts renamed to test/browser/column/headerCellClass.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Column, ColumnGroup } from '../../src';
2-
import { cellClassname } from '../../src/style/cell';
1+
import type { Column, ColumnGroup } from '../../../src';
2+
import { cellClassname } from '../../../src/style/cell';
33
import { getHeaderCells, setup } from '../utils';
44

55
test('headerCellClass is either nullish or a string', () => {

test/column/key.test.ts renamed to test/browser/column/key.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Column } from '../../src';
1+
import type { Column } from '../../../src';
22
import { setup } from '../utils';
33

44
test('key is escaped in query selectors', () => {

test/column/name.test.tsx renamed to test/browser/column/name.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Column } from '../../src';
1+
import type { Column } from '../../../src';
22
import { getHeaderCells, setup } from '../utils';
33

44
test('name is either a string or an element', () => {

test/column/renderCell.test.tsx renamed to test/browser/column/renderCell.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid from '../../src';
6-
import type { Column } from '../../src';
5+
import DataGrid from '../../../src';
6+
import type { Column } from '../../../src';
77
import { getCells, getCellsAtRowIndex, setup } from '../utils';
88

99
interface Row {

test/column/renderEditCell.test.tsx renamed to test/browser/column/renderEditCell.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { createPortal } from 'react-dom';
33
import { act, render, screen, waitFor } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55

6-
import DataGrid from '../../src';
7-
import type { Column, DataGridProps } from '../../src';
6+
import DataGrid from '../../../src';
7+
import type { Column, DataGridProps } from '../../../src';
88
import { getCellsAtRowIndex, getGrid, getSelectedCell, scrollGrid } from '../utils';
99

1010
interface Row {

test/column/renderHeaderCell.test.tsx renamed to test/browser/column/renderHeaderCell.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Column } from '../../src';
1+
import type { Column } from '../../../src';
22
import { getHeaderCells, setup } from '../utils';
33

44
test('renderHeaderCell is either undefined or a component', () => {

test/column/renderSummaryCell.test.tsx renamed to test/browser/column/renderSummaryCell.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Column } from '../../src';
1+
import type { Column } from '../../../src';
22
import { getCells, setup } from '../utils';
33

44
interface SummaryRow {

test/column/resizable.test.tsx renamed to test/browser/column/resizable.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { act } from 'react';
22
import { commands, userEvent } from '@vitest/browser/context';
33

4-
import type { Column } from '../../src';
5-
import { resizeHandleClassname } from '../../src/HeaderCell';
4+
import type { Column } from '../../../src';
5+
import { resizeHandleClassname } from '../../../src/HeaderCell';
66
import { getGrid, getHeaderCells, setup } from '../utils';
77

88
interface Row {

test/column/summaryCellClass.test.ts renamed to test/browser/column/summaryCellClass.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Column } from '../../src';
2-
import { cellClassname as cellClass } from '../../src/style/cell';
3-
import { summaryCellClassname } from '../../src/SummaryCell';
1+
import type { Column } from '../../../src';
2+
import { cellClassname as cellClass } from '../../../src/style/cell';
3+
import { summaryCellClassname } from '../../../src/SummaryCell';
44
import { getCells, setup } from '../utils';
55

66
interface SummaryRow {

test/columnOrder.test.tsx renamed to test/browser/columnOrder.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render } from '@testing-library/react';
22

3-
import DataGrid, { SelectColumn, TreeDataGrid } from '../src';
4-
import type { Column } from '../src';
3+
import DataGrid, { SelectColumn, TreeDataGrid } from '../../src';
4+
import type { Column } from '../../src';
55
import { getHeaderCells } from './utils';
66

77
const frozen1: Column<unknown> = {

test/copyPaste.test.tsx renamed to test/browser/copyPaste.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState } from 'react';
22
import { render } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid from '../src';
6-
import type { Column, PasteEvent } from '../src';
5+
import DataGrid from '../../src';
6+
import type { Column, PasteEvent } from '../../src';
77
import { copySelectedCell, getCellsAtRowIndex, getSelectedCell, pasteSelectedCell } from './utils';
88

99
interface Row {

test/direction.test.ts renamed to test/browser/direction.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import userEvent from '@testing-library/user-event';
22

3-
import type { Column } from '../src';
3+
import type { Column } from '../../src';
44
import { getGrid, getSelectedCell, setup } from './utils';
55

66
interface Row {

test/dragFill.test.tsx renamed to test/browser/dragFill.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState } from 'react';
22
import { render } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid from '../src';
6-
import type { Column, FillEvent } from '../src';
5+
import DataGrid from '../../src';
6+
import type { Column, FillEvent } from '../../src';
77
import { getCellsAtRowIndex, getRows } from './utils';
88

99
interface Row {

test/events.test.tsx renamed to test/browser/events.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

4-
import DataGrid from '../src';
5-
import type { Column, DataGridProps } from '../src';
4+
import DataGrid from '../../src';
5+
import type { Column, DataGridProps } from '../../src';
66
import { getCellsAtRowIndex } from './utils';
77

88
interface Row {

test/keyboardNavigation.test.tsx renamed to test/browser/keyboardNavigation.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

4-
import type { Column } from '../src';
5-
import DataGrid, { SelectColumn } from '../src';
4+
import type { Column } from '../../src';
5+
import DataGrid, { SelectColumn } from '../../src';
66
import {
77
getCellsAtRowIndex,
88
getSelectedCell,

test/renderers.test.tsx renamed to test/browser/renderers.test.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { useState } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid, { DataGridDefaultRenderersProvider, renderSortIcon, SelectColumn } from '../src';
6-
import type { Column, DataGridProps, RenderSortStatusProps, SortColumn } from '../src';
5+
import DataGrid, {
6+
DataGridDefaultRenderersProvider,
7+
renderSortIcon,
8+
SelectColumn
9+
} from '../../src';
10+
import type { Column, DataGridProps, RenderSortStatusProps, SortColumn } from '../../src';
711
import { getHeaderCells, getRows, setup } from './utils';
812

913
interface Row {

test/rowClass.test.ts renamed to test/browser/rowClass.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Column } from '../src';
2-
import { rowClassname } from '../src/style/row';
1+
import type { Column } from '../../src';
2+
import { rowClassname } from '../../src/style/row';
33
import { getRows, setup } from './utils';
44

55
interface Row {

test/rowHeight.test.ts renamed to test/browser/rowHeight.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

4-
import type { Column, DataGridProps } from '../src';
4+
import type { Column, DataGridProps } from '../../src';
55
import { getRows, setup } from './utils';
66

77
type Row = number;

test/rowSelection.test.tsx renamed to test/browser/rowSelection.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState } from 'react';
22
import { render, screen, within } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid, { SelectColumn } from '../src';
6-
import type { Column } from '../src';
5+
import DataGrid, { SelectColumn } from '../../src';
6+
import type { Column } from '../../src';
77
import { getCellsAtRowIndex, getRows } from './utils';
88

99
interface Row {

test/scrollToCell.test.tsx renamed to test/browser/scrollToCell.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useRef } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import type { Column, DataGridHandle } from '../src';
6-
import DataGrid from '../src';
7-
import type { PartialPosition } from '../src/ScrollToCell';
5+
import type { Column, DataGridHandle } from '../../src';
6+
import DataGrid from '../../src';
7+
import type { PartialPosition } from '../../src/ScrollToCell';
88
import { getGrid } from './utils';
99

1010
type Row = undefined;

test/sorting.test.tsx renamed to test/browser/sorting.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

5-
import DataGrid from '../src';
6-
import type { Column, SortColumn } from '../src/types';
5+
import DataGrid from '../../src';
6+
import type { Column, SortColumn } from '../../src/types';
77
import { getHeaderCells } from './utils';
88

99
const columns: readonly Column<never>[] = [

test/utils.tsx renamed to test/browser/utils.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { act, render, screen } from '@testing-library/react';
22
import { userEvent } from '@vitest/browser/context';
33
import { css } from '@linaria/core';
44

5-
import DataGrid from '../src/';
6-
import type { DataGridProps } from '../src/';
5+
import DataGrid from '../../src';
6+
import type { DataGridProps } from '../../src';
77

88
export function setup<R, SR, K extends React.Key = React.Key>(props: DataGridProps<R, SR, K>) {
99
render(

test/virtualization.test.ts renamed to test/browser/virtualization.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Column } from '../src';
1+
import type { Column } from '../../src';
22
import {
33
getCells,
44
getCellsAtRowIndex,

test/ssr.test.tsx renamed to test/node/ssr.test.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// @vitest-environment node
21
import { renderToString } from 'react-dom/server';
32

4-
import DataGrid from '../src';
5-
import type { Column } from '../src';
3+
import DataGrid from '../../src';
4+
import type { Column } from '../../src';
65

76
interface Row {
87
id: number;
@@ -23,14 +22,10 @@ function App() {
2322
return <DataGrid columns={columns} rows={rows} />;
2423
}
2524

26-
// biome-ignore lint/suspicious/noSkippedTests: <explanation>
27-
test.skip('basic server-side rendering (SSR) support', () => {
28-
// make sure we're not running in the JSDOM environment
25+
test('basic server-side rendering (SSR) support', () => {
26+
// make sure we're not running in a browser environment
2927
expect(globalThis.window).toBeUndefined();
3028

3129
const html = renderToString(<App />);
3230
expect(html).not.toHaveLength(0);
33-
34-
// make sure `@testing-library/jest-dom` does not polyfill `window.CSS`
35-
expect(typeof CSS).toBe('undefined');
3631
});

tsconfig.vite.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"skipLibCheck": true,
55
"types": ["@vitest/browser/providers/playwright"]
66
},
7-
"include": ["vite.config.ts"]
7+
"include": ["vite.config.ts", "vitest.workspace.ts"]
88
}

vite.config.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,9 @@ import react from '@vitejs/plugin-react';
22
import wyw from '@wyw-in-js/vite';
33
import browserslist from 'browserslist';
44
import { defineConfig } from 'vite';
5-
import type { BrowserCommand } from 'vitest/node';
65

76
const isCI = process.env.CI === 'true';
87

9-
// TODO: remove when `userEvent.pointer` is supported
10-
const resizeColumn: BrowserCommand<[resizeBy: number]> = async (context, resizeBy) => {
11-
const page = context.page;
12-
const frame = await context.frame();
13-
const resizeHandle = frame.locator('[role="columnheader"][aria-colindex="2"] div');
14-
const { x, y } = (await resizeHandle.boundingBox())!;
15-
await resizeHandle.hover({
16-
position: { x: 5, y: 5 }
17-
});
18-
await page.mouse.down();
19-
await page.mouse.move(x + resizeBy + 5, y);
20-
await page.mouse.up();
21-
};
22-
238
export default defineConfig(({ command }) => ({
249
base: '/react-data-grid/',
2510
cacheDir: '.cache/vite',
@@ -56,14 +41,7 @@ export default defineConfig(({ command }) => ({
5641
},
5742
testTimeout: isCI ? 10000 : 5000,
5843
setupFiles: ['test/setup.ts'],
59-
browser: {
60-
enabled: true,
61-
name: 'chromium',
62-
provider: 'playwright',
63-
commands: { resizeColumn },
64-
viewport: { width: 1920, height: 1080 },
65-
headless: true
66-
},
44+
reporters: ['basic'],
6745
restoreMocks: true,
6846
sequence: {
6947
shuffle: true

0 commit comments

Comments
 (0)