diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d37aa75c..85385cb5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,11 +1,11 @@ -name: Run jest tests +name: Run unit tests on: pull_request: {} push: branches: [livekit, full-mesh] jobs: - jest: - name: Run jest tests + vitest: + name: Run vitest tests runs-on: ubuntu-latest steps: - name: Checkout code @@ -16,7 +16,7 @@ jobs: cache: "yarn" - name: Install dependencies run: "yarn install" - - name: Jest + - name: Vitest run: "yarn run test" - name: Upload to codecov uses: codecov/codecov-action@v4 diff --git a/package.json b/package.json index c95e16f7..4c443f22 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "lint:types": "tsc", "i18n": "node_modules/i18next-parser/bin/cli.js", "i18n:check": "node_modules/i18next-parser/bin/cli.js --fail-on-warnings --fail-on-update", - "test": "jest", + "test": "vitest", + "test:coverage": "vitest run --coverage", "backend": "docker-compose -f backend-docker-compose.yml up" }, "dependencies": { @@ -88,14 +89,12 @@ "@react-spring/rafz": "^9.7.3", "@react-types/dialog": "^3.5.5", "@sentry/vite-plugin": "^2.0.0", - "@testing-library/jest-dom": "^6.0.0", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.5.1", "@types/content-type": "^1.1.5", "@types/dom-screen-wake-lock": "^1.0.1", "@types/dompurify": "^3.0.2", "@types/grecaptcha": "^3.0.4", - "@types/jest": "^29.5.5", "@types/node": "^20.0.0", "@types/react-router-dom": "^5.3.3", "@types/request": "^2.48.8", @@ -116,37 +115,14 @@ "eslint-plugin-react-hooks": "^4.5.0", "eslint-plugin-unicorn": "^51.0.0", "i18next-parser": "^8.0.0", - "identity-obj-proxy": "^3.0.0", - "jest": "^29.2.2", - "jest-environment-jsdom": "^29.3.1", - "jest-mock": "^29.5.0", + "jsdom": "^24.0.0", "prettier": "^3.0.0", "sass": "^1.42.1", "typescript": "^5.1.6", "typescript-eslint-language-service": "^5.0.5", "vite": "^5.0.0", "vite-plugin-html-template": "^1.1.0", - "vite-plugin-svgr": "^4.0.0" - }, - "jest": { - "testEnvironment": "./test/environment.ts", - "testMatch": [ - "/test/**/*-test.[jt]s?(x)" - ], - "transformIgnorePatterns": [ - "/node_modules/(?!d3)+$", - "/node_modules/(?!internmap)+$" - ], - "moduleNameMapper": { - "\\.css$": "identity-obj-proxy", - "\\.svg\\?react$": "/test/mocks/svgr.ts", - "^\\./IndexedDBWorker\\?worker$": "/test/mocks/workerMock.ts", - "^\\./olm$": "/test/mocks/olmMock.ts" - }, - "collectCoverage": true, - "coverageReporters": [ - "text", - "cobertura" - ] + "vite-plugin-svgr": "^4.0.0", + "vitest": "^1.2.2" } } diff --git a/test/Toast-test.tsx b/test/Toast-test.tsx index 88cfbf4b..6b573523 100644 --- a/test/Toast-test.tsx +++ b/test/Toast-test.tsx @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { vi } from "vitest"; import { screen, render } from "@testing-library/react"; import { Toast } from "../src/Toast"; import userEvent from "@testing-library/user-event"; @@ -35,7 +36,7 @@ test("Toast renders", () => { }); test("Toast dismisses when clicked", async () => { - const onDismiss = jest.fn(); + const onDismiss = vi.fn(); render( Hello world! @@ -47,13 +48,13 @@ test("Toast dismisses when clicked", async () => { test("Toast dismisses itself after the specified timeout", async () => { withFakeTimers(() => { - const onDismiss = jest.fn(); + const onDismiss = vi.fn(); render( Hello world! , ); - jest.advanceTimersByTime(2000); + vi.advanceTimersByTime(2000); expect(onDismiss).toHaveBeenCalled(); }); }); diff --git a/test/UrlParams-test.ts b/test/UrlParams-test.ts index e0eb7c29..eb03d976 100644 --- a/test/UrlParams-test.ts +++ b/test/UrlParams-test.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { mocked } from "jest-mock"; +import { vi } from "vitest"; import { getRoomIdentifierFromUrl } from "../src/UrlParams"; import { Config } from "../src/config/Config"; @@ -24,11 +24,11 @@ const ROOM_ID = "!d45f138fsd"; const ORIGIN = "https://call.element.io"; const HOMESERVER = "call.ems.host"; -jest.mock("../src/config/Config"); +vi.mock("../src/config/Config"); describe("UrlParams", () => { beforeAll(() => { - mocked(Config.defaultServerName).mockReturnValue("call.ems.host"); + vi.mocked(Config.defaultServerName).mockReturnValue("call.ems.host"); }); describe("handles URL with /room/", () => { diff --git a/test/__snapshots__/Toast-test.tsx.snap b/test/__snapshots__/Toast-test.tsx.snap index 64822136..7edfdcf7 100644 --- a/test/__snapshots__/Toast-test.tsx.snap +++ b/test/__snapshots__/Toast-test.tsx.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`Toast renders 1`] = `