Skip to content

Commit 68c7af3

Browse files
committed
Claude-backed review of why some tests are slower since migrating to vitest. This simplifies things a lot.
1 parent c9bc707 commit 68c7af3

25 files changed

Lines changed: 252 additions & 266 deletions

.github/workflows/pr.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,13 @@ jobs:
5656
- name: Install dependencies
5757
run: pnpm install --frozen-lockfile
5858

59+
- name: Restore Vitest cache
60+
uses: actions/cache@v4
61+
with:
62+
path: node_modules/.vite
63+
key: vitest-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('vitest.config.ts', 'vite.config.base.ts') }}
64+
restore-keys: |
65+
vitest-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-
66+
5967
- name: Run component tests
6068
run: pnpm test

__mocks__/react-router-dom.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { PropsWithChildren } from 'react';
2+
import type { Mock } from 'vitest';
23

3-
export const navigateMock = vi.fn();
4+
export const navigateMock: Mock = vi.fn();
45

5-
export const useLocation = vi.fn();
6-
export const useRouteMatch = vi.fn();
7-
export const useNavigate = () => navigateMock;
8-
export const useParams = vi.fn();
6+
export const useLocation: Mock = vi.fn();
7+
export const useRouteMatch: Mock = vi.fn();
8+
export const useNavigate = (): Mock => navigateMock;
9+
export const useParams: Mock = vi.fn();
910
export const withRouter = (children: React.ReactNode) => children;
1011
export const Route = ({
1112
path = 'index',

eslint.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ export default [
4646
globals: {
4747
...globals.browser,
4848
...globals.node,
49-
...globals.jest,
50-
expect: true,
49+
...globals.vitest,
5150
__DEV__: true,
5251
},
5352

jest.config.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@
9797
"test:ui": "vitest --ui",
9898
"lint": "eslint --cache --ext=.ts --ext=.tsx src/"
9999
},
100-
"eslintConfig": {
101-
"extends": [
102-
"react-app",
103-
"react-app/jest"
104-
]
105-
},
106100
"browserslist": {
107101
"production": [
108102
">0.2%",

src/components/ClusterHealthManager/ClusterHealthManager.test.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,12 @@ const mockNodeStatus = (rows: [][]) => {
3333
};
3434

3535
describe('ClusterHealthManager', () => {
36-
beforeAll(() => {
37-
server.listen();
38-
});
39-
4036
afterEach(() => {
41-
server.resetHandlers();
4237
act(() => {
4338
useClusterHealthStore.setState({ clusterHealth: {} });
4439
});
4540
});
4641

47-
afterAll(() => {
48-
server.close();
49-
});
50-
5142
describe('load', () => {
5243
it('populates the store with load data when nodes are available', async () => {
5344
setup();

src/components/CopyToClipboard/CopyToClipboard.test.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import CopyToClipboard, { CopyToClipboardProps } from './CopyToClipboard';
2-
import { expectAntdMessage, flushAntdPortals, render, screen } from 'test/testUtils';
2+
import { expectAntdMessage, render, screen, withAntdPortalCleanup } from 'test/testUtils';
33

44
const defaultProps: CopyToClipboardProps = {
55
textToCopy: 'example-string',
@@ -15,10 +15,6 @@ const setup = (props: Partial<CopyToClipboardProps> = {}) => {
1515
};
1616

1717
describe('the CopyToClipboard component', () => {
18-
afterEach(async () => {
19-
await flushAntdPortals();
20-
});
21-
2218
it('displays the child contents', () => {
2319
setup();
2420

@@ -32,6 +28,8 @@ describe('the CopyToClipboard component', () => {
3228
});
3329

3430
describe('when the user clicks the button', () => {
31+
withAntdPortalCleanup();
32+
3533
it('copies the text to the clipboard', async () => {
3634
const { user } = setup();
3735
const writeTextMock = vi

src/components/NotificationHandler/NotificationHandler.test.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import { disableConsole, flushAntdPortals, render, screen, waitFor } from 'test/testUtils';
1+
import { disableConsole, render, screen, waitFor, withAntdPortalCleanup } from 'test/testUtils';
22
import NotificationHandler from './NotificationHandler';
33
import useSessionStore from 'state/session';
44

55
const setup = () => render(<NotificationHandler />);
66

77
describe('The NotificationHandler component', () => {
8+
withAntdPortalCleanup();
9+
810
beforeAll(() => {
911
// disabled the console here as the notifications code will be
1012
// refactored entirely in the near future
1113
disableConsole('error');
1214
});
1315

14-
afterEach(async () => {
15-
await flushAntdPortals();
16-
});
17-
1816
it('renders nothing if there is no notification to show', () => {
1917
const { container } = setup();
2018

src/components/NotificationHandler/notificationPresets.test.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import { notification } from 'antd';
2-
import { actWithFakeTimers, disableConsole } from 'test/testUtils';
2+
import { actWithFakeTimers } from 'test/testUtils';
33
import { infoNotification } from './notificationPresets';
44

55
describe('the notification presets', () => {
6-
const notificationSpy = vi.spyOn(notification, 'open');
7-
8-
beforeAll(() => {
9-
// disabled the console here as the notifications code will be
10-
// refactored entirely in the near future
11-
disableConsole('error');
6+
const notificationSpy = vi.spyOn(notification, 'open').mockImplementation(() => {
7+
// Config-only tests — no portal render (avoids rc-motion act() warnings).
128
});
139

1410
afterEach(() => {
15-
notificationSpy.mockReset();
11+
notificationSpy.mockClear();
1612
});
1713

1814
afterAll(() => {

src/components/SQLEditor/SQLEditorSchemaTree.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'test/__mocks__/query';
88
import { useSchemaTreeMock } from 'test/__mocks__/useSchemaTreeMock';
99
import { act } from 'react';
10-
import { flushAntdPortals, render, screen, waitFor, within } from 'test/testUtils';
10+
import { render, screen, waitFor, withAntdPortalCleanup, within } from 'test/testUtils';
1111
import SQLEditorSchemaTree from './SQLEditorSchemaTree';
1212
import { postFetch } from 'src/swr/jwt/useSchemaTree';
1313

@@ -52,9 +52,8 @@ const setup = async () => {
5252

5353
describe('The SQLEditorSchemaTree component', () => {
5454
beforeEach(() => { vi.useFakeTimers({ shouldAdvanceTime: true }); });
55-
afterEach(async () => {
55+
afterEach(() => {
5656
vi.useRealTimers();
57-
await flushAntdPortals();
5857
});
5958

6059
describe('the schemas', () => {
@@ -138,6 +137,8 @@ describe('The SQLEditorSchemaTree component', () => {
138137
});
139138

140139
describe('the context menu', () => {
140+
withAntdPortalCleanup();
141+
141142
describe('the Copy SELECT button', () => {
142143
it('copies the SELECT statement', async () => {
143144
const schema = schemaTableColumns.find(

0 commit comments

Comments
 (0)