From 8dfc33777c5498780624812b7c7bed59c7aeb2c8 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Tue, 1 Aug 2023 16:05:47 +0200 Subject: [PATCH] Migrate to vitest --- package.json | 12 +- .../ActionControl/ActionControl.test.tsx | 3 +- .../__snapshots__/ActionControl.test.tsx.snap | 30 +- src/components/Alert/Alert.test.tsx | 3 +- .../Alert/__snapshots__/Alert.test.tsx.snap | 24 +- src/components/Avatar/Avatar.test.tsx | 1 + src/components/Avatar/AvatarStack.test.tsx | 1 + .../Avatar/__snapshots__/Avatar.test.tsx.snap | 6 +- .../__snapshots__/AvatarStack.test.tsx.snap | 6 +- src/components/Badge/Badge.test.tsx | 1 + .../Badge/__snapshots__/Badge.test.tsx.snap | 6 +- src/components/Button/Button.test.tsx | 3 +- .../Button/__snapshots__/Button.test.tsx.snap | 6 +- src/components/Checkbox/Checkbox.test.tsx | 1 + .../__snapshots__/Checkbox.test.tsx.snap | 22 +- src/components/Form/Controls/MFA/MFA.test.tsx | 1 + .../MFA/__snapshots__/MFA.test.tsx.snap | 26 +- .../Form/Controls/Password/Password.test.tsx | 1 + src/components/Link/Link.test.tsx | 1 + .../Link/__snapshots__/Link.test.tsx.snap | 6 +- src/components/Radio/Radio.test.tsx | 1 + .../Radio/__snapshots__/Radio.test.tsx.snap | 8 +- src/components/Toggle/Toggle.test.tsx | 1 + .../Toggle/__snapshots__/Toggle.test.tsx.snap | 8 +- src/components/Typography/Body.test.tsx | 1 + src/components/Typography/Heading.test.tsx | 1 + .../__snapshots__/Body.test.tsx.snap | 4 +- .../__snapshots__/Heading.test.tsx.snap | 4 +- .../__ComponentTemplate__.test.tsx | 1 + .../__ComponentTemplate__.test.tsx.snap | 6 +- tsconfig.json | 2 +- vite.config.ts | 8 +- yarn.lock | 1273 +++++++---------- 33 files changed, 619 insertions(+), 859 deletions(-) diff --git a/package.json b/package.json index b22f8948..425da612 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint": "yarn lint:js && yarn lint:styles", "lint:js": "eslint --max-warnings=0 .", "lint:styles": "npx stylelint \"**/*.css\"", - "test": "jest", + "test": "vitest", "prepercy": "node scripts/disableStoryStore7.js && yarn build-storybook", "percy": "percy storybook ./storybook-static", "postpercy": "git checkout .storybook/main.ts", @@ -64,7 +64,6 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", - "@types/jest": "^29.5.1", "@types/lodash-es": "^4.17.7", "@types/node": "^18.16.0", "@types/react": "^18.0.38", @@ -80,9 +79,7 @@ "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-react": "^7.32.2", "eslint-plugin-storybook": "^0.6.12", - "jest": "^29.5.0", - "jest-css-modules": "^2.1.0", - "jest-environment-jsdom": "^29.5.0", + "jsdom": "^22.1.0", "prettier": "^2.8.7", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -93,9 +90,10 @@ "stylelint": "^15.2.0", "stylelint-config-standard": "^30.0.1", "typescript": "^5.1.6", - "vite": "^4.3.5", + "vite": "^4.4.8", "vite-plugin-dts": "^3.4.0", - "vite-plugin-svgr": "^3.2.0" + "vite-plugin-svgr": "^3.2.0", + "vitest": "^0.33.0" }, "dependencies": { "@radix-ui/react-form": "^0.0.2", diff --git a/src/components/ActionControl/ActionControl.test.tsx b/src/components/ActionControl/ActionControl.test.tsx index 2a488032..5fb2f139 100644 --- a/src/components/ActionControl/ActionControl.test.tsx +++ b/src/components/ActionControl/ActionControl.test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { vi, describe, it, expect } from "vitest"; import { fireEvent, getByLabelText, render } from "@testing-library/react"; import React from "react"; @@ -35,7 +36,7 @@ describe("ActionControl", () => { }); it("trigger the action", () => { - const spy = jest.fn(); + const spy = vi.fn(); const { container } = render( renders 1`] = `
+ xmlns="http://www.w3.org/2000/svg" + > + + +
diff --git a/src/components/Alert/Alert.test.tsx b/src/components/Alert/Alert.test.tsx index 466fdd56..de798606 100644 --- a/src/components/Alert/Alert.test.tsx +++ b/src/components/Alert/Alert.test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { vi, describe, it, expect } from "vitest"; import { fireEvent, getByLabelText, @@ -45,7 +46,7 @@ describe("Alert", () => { }); it("can have a close button", async () => { - const spy = jest.fn(); + const spy = vi.fn(); const { container } = render( Click me! diff --git a/src/components/Alert/__snapshots__/Alert.test.tsx.snap b/src/components/Alert/__snapshots__/Alert.test.tsx.snap index 25685803..5db022b1 100644 --- a/src/components/Alert/__snapshots__/Alert.test.tsx.snap +++ b/src/components/Alert/__snapshots__/Alert.test.tsx.snap @@ -1,27 +1,35 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Alert renders 1`] = ` +exports[`Alert > renders 1`] = `
+ xmlns="http://www.w3.org/2000/svg" + > + +

Title

Success!

diff --git a/src/components/Avatar/Avatar.test.tsx b/src/components/Avatar/Avatar.test.tsx index 67f9318b..b535ff1e 100644 --- a/src/components/Avatar/Avatar.test.tsx +++ b/src/components/Avatar/Avatar.test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { describe, beforeEach, expect, it } from "vitest"; import { render, waitFor } from "@testing-library/react"; import React from "react"; diff --git a/src/components/Avatar/AvatarStack.test.tsx b/src/components/Avatar/AvatarStack.test.tsx index be37bc9f..b490bb82 100644 --- a/src/components/Avatar/AvatarStack.test.tsx +++ b/src/components/Avatar/AvatarStack.test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { describe, it, expect, beforeEach, afterEach } from "vitest"; import { render } from "@testing-library/react"; import React from "react"; diff --git a/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap b/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap index 38cd3a44..b2c0a6b5 100644 --- a/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap +++ b/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap @@ -1,10 +1,10 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Avatar renders the image-less avatar 1`] = ` +exports[`Avatar > renders the image-less avatar 1`] = ` renders 1`] = `
`; diff --git a/src/components/Badge/Badge.test.tsx b/src/components/Badge/Badge.test.tsx index 9d82d4c0..11c636ba 100644 --- a/src/components/Badge/Badge.test.tsx +++ b/src/components/Badge/Badge.test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { describe, it, expect } from "vitest"; import { render } from "@testing-library/react"; import React from "react"; diff --git a/src/components/Badge/__snapshots__/Badge.test.tsx.snap b/src/components/Badge/__snapshots__/Badge.test.tsx.snap index 5658c097..554ec866 100644 --- a/src/components/Badge/__snapshots__/Badge.test.tsx.snap +++ b/src/components/Badge/__snapshots__/Badge.test.tsx.snap @@ -1,9 +1,9 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Badge renders 1`] = ` +exports[`Badge > renders 1`] = ` diff --git a/src/components/Button/Button.test.tsx b/src/components/Button/Button.test.tsx index 6cdaf91d..02afc52b 100644 --- a/src/components/Button/Button.test.tsx +++ b/src/components/Button/Button.test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { vi, describe, it } from "vitest"; import React from "react"; import { getByRole, render } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; @@ -27,7 +28,7 @@ describe("Button", () => { }); it("can be clicked", async () => { - const spy = jest.fn(); + const spy = vi.fn(); const { container } = render(); const user = userEvent.setup(); diff --git a/src/components/Button/__snapshots__/Button.test.tsx.snap b/src/components/Button/__snapshots__/Button.test.tsx.snap index 0d3a9dd1..16515c36 100644 --- a/src/components/Button/__snapshots__/Button.test.tsx.snap +++ b/src/components/Button/__snapshots__/Button.test.tsx.snap @@ -1,9 +1,9 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Button renders 1`] = ` +exports[`Button > renders 1`] = `