Skip to content

Commit 47944a7

Browse files
authored
Migrate @comet/admin tests to Vitest (#4972)
1 parent 0031d19 commit 47944a7

21 files changed

+125
-214
lines changed

knip.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"packages/admin/admin": {
3737
"project": ["./src/**/*.{ts,tsx}"],
38-
"ignoreDependencies": ["jest-junit", "@mui/x-data-grid-pro", "@mui/x-date-pickers-pro", "msw"],
38+
"ignoreDependencies": ["@mui/x-data-grid-pro", "@mui/x-date-pickers-pro", "msw", "jsdom"],
3939
"ignore": [".storybook/middleware.js"]
4040
},
4141
"packages/admin/admin-color-picker": {

packages/admin/admin/jest.config.ts

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

packages/admin/admin/package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"start:babel": "pnpm exec babel ./src -x \".ts,.tsx\" -d lib -w",
3030
"start:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --watch --preserveWatchOutput",
3131
"storybook": "storybook dev -p 26646 --no-open",
32-
"test": "jest",
33-
"test:watch": "jest --watch"
32+
"test": "vitest --run",
33+
"test:watch": "vitest --watch"
3434
},
3535
"dependencies": {
3636
"@comet/admin-icons": "workspace:*",
@@ -73,7 +73,6 @@
7373
"@types/file-saver": "^2.0.7",
7474
"@types/final-form-set-field-data": "^1.0.3",
7575
"@types/history": "^4.7.11",
76-
"@types/jest": "^29.5.14",
7776
"@types/lodash.debounce": "^4.0.9",
7877
"@types/lodash.isequal": "^4.5.8",
7978
"@types/node": "^24.9.1",
@@ -86,9 +85,6 @@
8685
"final-form": "^4.20.10",
8786
"graphql": "^16.0.0",
8887
"history": "^4.10.1",
89-
"jest": "^29.7.0",
90-
"jest-environment-jsdom": "^29.7.0",
91-
"jest-junit": "^16.0.0",
9288
"msw": "^2.10.4",
9389
"npm-run-all2": "^8.0.0",
9490
"prettier": "^3.6.2",
@@ -102,8 +98,9 @@
10298
"rimraf": "^6.1.2",
10399
"storybook": "^9.1.10",
104100
"storybook-addon-tag-badges": "^2.0.1",
105-
"ts-jest": "^29.4.0",
106-
"typescript": "5.9.3"
101+
"typescript": "5.9.3",
102+
"vite-tsconfig-paths": "^6.0.3",
103+
"vitest": "^4.0.16"
107104
},
108105
"peerDependencies": {
109106
"@apollo/client": "^3.7.0",

packages/admin/admin/setupTests.ts

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

packages/admin/admin/src/EditDialog.routerTabs.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { createMemoryHistory } from "history";
55
import { type ReactNode, type RefObject, useRef } from "react";
66
import { useIntl } from "react-intl";
77
import { Router } from "react-router";
8-
import { render, screen, waitFor } from "test-utils";
8+
import { cleanup, render, screen, waitFor } from "test-utils";
9+
import { afterEach, describe, expect, it } from "vitest";
910

1011
import { Button } from "./common/buttons/Button";
1112
import { FillSpace } from "./common/FillSpace";
@@ -124,6 +125,8 @@ describe("EditDialog with Stack, Router Tabs and Grid", () => {
124125
);
125126
}
126127

128+
afterEach(cleanup);
129+
127130
it("should not open edit dialog when navigating to the products page", async () => {
128131
const history = createMemoryHistory({
129132
initialEntries: ["/", "/products"],

packages/admin/admin/src/EditDialog.stackRouterTabs.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { type ReactNode, type RefObject, useRef } from "react";
66
import { useIntl } from "react-intl";
77
import { Router } from "react-router";
88
import { render, screen, waitFor, within } from "test-utils";
9+
import { describe, expect, it } from "vitest";
910

1011
import { Button } from "./common/buttons/Button";
1112
import { FillSpace } from "./common/FillSpace";

packages/admin/admin/src/EditDialog.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import userEvent from "@testing-library/user-event";
2-
import { render, screen, waitFor } from "test-utils";
2+
import { cleanup, render, screen, waitFor } from "test-utils";
3+
import { afterEach, describe, expect, test, vi } from "vitest";
34

45
import { Button } from "./common/buttons/Button";
56
import { useEditDialog } from "./EditDialog";
@@ -9,9 +10,11 @@ import { FinalFormInput } from "./form/FinalFormInput";
910

1011
describe("EditDialog", () => {
1112
describe("onAfterSave", () => {
13+
afterEach(cleanup);
14+
1215
test("Should call onAfterSave when clicking save button", async () => {
1316
const user = userEvent.setup();
14-
const onAfterSave = jest.fn();
17+
const onAfterSave = vi.fn();
1518

1619
function Story() {
1720
const [EditDialog, , editDialogApi] = useEditDialog();
@@ -51,7 +54,7 @@ describe("EditDialog", () => {
5154

5255
test("Should call onAfterSave when pressing Enter", async () => {
5356
const user = userEvent.setup();
54-
const onAfterSave = jest.fn();
57+
const onAfterSave = vi.fn();
5558

5659
function Story() {
5760
const [EditDialog, , editDialogApi] = useEditDialog();

packages/admin/admin/src/FinalForm.InTabs.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createTheme } from "@mui/material/styles";
22
import { IntlProvider } from "react-intl";
3-
import { fireEvent, render, waitFor } from "test-utils";
3+
import { cleanup, fireEvent, render, waitFor } from "test-utils";
4+
import { afterEach, expect, test } from "vitest";
45

56
import { FinalForm } from "./FinalForm";
67
import { Field } from "./form/Field";
@@ -14,6 +15,8 @@ import { StackLink } from "./stack/StackLink";
1415
import { StackSwitch } from "./stack/Switch";
1516
import { RouterTab, RouterTabs } from "./tabs/RouterTabs";
1617

18+
afterEach(cleanup);
19+
1720
test("Form DirtyPrompt for inner Tabs", async () => {
1821
function Story() {
1922
return (

packages/admin/admin/src/apollo/filterByFragment.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copied and adapted from https://github.com/apollographql/apollo-client/blob/release-2.x/packages/graphql-anywhere/src/__tests__/utilities.ts
2-
32
import { disableFragmentWarnings, gql } from "@apollo/client";
3+
import { describe, expect, it } from "vitest";
4+
5+
import { filterByFragment } from "./filterByFragment";
46

57
// Turn off warnings for repeated fragment names
68
disableFragmentWarnings();
79

8-
import { filterByFragment } from "./filterByFragment";
9-
1010
describe("filterByFragment", () => {
1111
describe("with a single query", () => {
1212
const doc = gql`

packages/admin/admin/src/dataGrid/muiGridFilterToGql.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GridLogicOperator } from "@mui/x-data-grid";
22
import { type GridFilterModel } from "@mui/x-data-grid/models/gridFilterModel";
3+
import { describe, expect, it } from "vitest";
34

45
import { type GridColDef } from "./GridColDef";
56
import { muiGridFilterToGql } from "./muiGridFilterToGql";

0 commit comments

Comments
 (0)