From 261d65772c0955e576de9bf31e8a04d1bda0391d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Mon, 14 Oct 2024 14:54:36 +0200 Subject: [PATCH] test(sanity): migrate remaining tests to vitest --- .../FormBuilderInputErrorBoundary.test.tsx | 10 +++---- .../utils/__test__/eventChainUtils.test.ts | 2 +- .../__test__/sequentializeEvents.test.ts | 2 +- .../WorkspaceRouterProvider.test.tsx | 26 +++++++++---------- .../src/core/util/__tests__/rxSwr.test.ts | 2 +- .../__test__/ErrorBoundary.test.tsx | 10 +++---- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/sanity/src/core/form/studio/FormBuilderInputErrorBoundary.test.tsx b/packages/sanity/src/core/form/studio/FormBuilderInputErrorBoundary.test.tsx index 297b489ac0e..79db7b51289 100644 --- a/packages/sanity/src/core/form/studio/FormBuilderInputErrorBoundary.test.tsx +++ b/packages/sanity/src/core/form/studio/FormBuilderInputErrorBoundary.test.tsx @@ -1,18 +1,18 @@ -import {beforeAll, describe, expect, it, jest} from '@jest/globals' import {render, screen} from '@testing-library/react' import {type SanityClient} from 'sanity' +import {beforeAll, describe, expect, it, vi} from 'vitest' import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient' import {createTestProvider} from '../../../../test/testUtils/TestProvider' import {FormBuilderInputErrorBoundary} from './FormBuilderInputErrorBoundary' -jest.mock('use-hot-module-reload', () => ({ - useHotModuleReload: jest.fn(), +vi.mock('use-hot-module-reload', () => ({ + useHotModuleReload: vi.fn(), })) describe('FormBuilderInputErrorBoundary', () => { beforeAll(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) it('renders children when there is no error', async () => { @@ -26,7 +26,7 @@ describe('FormBuilderInputErrorBoundary', () => { }) it('calls onUncaughtError when an error is caught', async () => { - const onUncaughtError = jest.fn() + const onUncaughtError = vi.fn() const ThrowErrorComponent = () => { throw new Error('An EXPECTED, testing error occurred!') diff --git a/packages/sanity/src/core/store/_legacy/document/utils/__test__/eventChainUtils.test.ts b/packages/sanity/src/core/store/_legacy/document/utils/__test__/eventChainUtils.test.ts index 94ef846e713..043c8fed5b6 100644 --- a/packages/sanity/src/core/store/_legacy/document/utils/__test__/eventChainUtils.test.ts +++ b/packages/sanity/src/core/store/_legacy/document/utils/__test__/eventChainUtils.test.ts @@ -1,4 +1,4 @@ -import {describe, expect, it} from '@jest/globals' +import {describe, expect, it} from 'vitest' import {discardChainTo, toOrderedChains} from '../eventChainUtils' import {mutationEvent} from './test-utils' diff --git a/packages/sanity/src/core/store/_legacy/document/utils/__test__/sequentializeEvents.test.ts b/packages/sanity/src/core/store/_legacy/document/utils/__test__/sequentializeEvents.test.ts index 87ea9fd485d..024c074492e 100644 --- a/packages/sanity/src/core/store/_legacy/document/utils/__test__/sequentializeEvents.test.ts +++ b/packages/sanity/src/core/store/_legacy/document/utils/__test__/sequentializeEvents.test.ts @@ -1,7 +1,7 @@ /* eslint-disable no-nested-ternary */ -import {expect, test} from '@jest/globals' import {from, lastValueFrom} from 'rxjs' import {toArray} from 'rxjs/operators' +import {expect, test} from 'vitest' import {type MutationPayload} from '../../buffered-doc' import {type ListenerEvent} from '../../getPairListener' diff --git a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx index 14044f080e0..97eadb626d2 100644 --- a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx +++ b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx @@ -1,34 +1,34 @@ -import {describe, expect, it, jest} from '@jest/globals' import {render, screen} from '@testing-library/react' import {type SanityClient, type Workspace} from 'sanity' +import {describe, expect, it, vi} from 'vitest' import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient' import {createTestProvider} from '../../../../test/testUtils/TestProvider' import {WorkspaceRouterProvider} from './WorkspaceRouterProvider' -jest.mock('../router/RouterHistoryContext', () => ({ +vi.mock('../router/RouterHistoryContext', () => ({ useRouterHistory: () => ({ location: {pathname: '/'}, - listen: jest.fn(), + listen: vi.fn(), }), })) -jest.mock('../router', () => ({ +vi.mock('../router', () => ({ createRouter: () => ({ - getBasePath: jest.fn(), - decode: jest.fn(), - isNotFound: jest.fn(), + getBasePath: vi.fn(), + decode: vi.fn(), + isNotFound: vi.fn(), }), })) -jest.mock('sanity/router', () => ({ +vi.mock('sanity/router', () => ({ RouterProvider: ({children}: {children: React.ReactNode}) =>
{children}
, IntentLink: () =>
IntentLink
, })) -jest.mock('./WorkspaceRouterProvider', () => ({ - ...(jest.requireActual('./WorkspaceRouterProvider') as object), - useRouterFromWorkspaceHistory: jest.fn(), +vi.mock('./WorkspaceRouterProvider', async () => ({ + ...(await vi.importActual('./WorkspaceRouterProvider')), + useRouterFromWorkspaceHistory: vi.fn(), })) describe('WorkspaceRouterProvider', () => { @@ -52,7 +52,7 @@ describe('WorkspaceRouterProvider', () => { currentUser: {}, authenticated: true, auth: {}, - getClient: jest.fn(), + getClient: vi.fn(), i18n: {}, __internal: {}, type: 'workspace', @@ -70,7 +70,7 @@ describe('WorkspaceRouterProvider', () => { }) it('calls onUncaughtError when an error is caught', async () => { - const onUncaughtError = jest.fn() + const onUncaughtError = vi.fn() const ThrowErrorComponent = () => { throw new Error('An EXPECTED, testing error occurred!') diff --git a/packages/sanity/src/core/util/__tests__/rxSwr.test.ts b/packages/sanity/src/core/util/__tests__/rxSwr.test.ts index 466349412e8..5fc37239f3c 100644 --- a/packages/sanity/src/core/util/__tests__/rxSwr.test.ts +++ b/packages/sanity/src/core/util/__tests__/rxSwr.test.ts @@ -1,6 +1,6 @@ -import {describe, expect, it} from '@jest/globals' import {lastValueFrom, timer} from 'rxjs' import {map, toArray} from 'rxjs/operators' +import {describe, expect, it} from 'vitest' import {createSWR} from '../rxSwr' diff --git a/packages/sanity/src/ui-components/errorBoundary/__test__/ErrorBoundary.test.tsx b/packages/sanity/src/ui-components/errorBoundary/__test__/ErrorBoundary.test.tsx index 988d0a43bb3..5e1751965ae 100644 --- a/packages/sanity/src/ui-components/errorBoundary/__test__/ErrorBoundary.test.tsx +++ b/packages/sanity/src/ui-components/errorBoundary/__test__/ErrorBoundary.test.tsx @@ -1,7 +1,7 @@ -import {beforeAll, describe, expect, it, jest} from '@jest/globals' import {studioTheme, ThemeProvider} from '@sanity/ui' import {render} from '@testing-library/react' import {type SanityClient} from 'sanity' +import {beforeAll, describe, expect, it, vi} from 'vitest' import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient' import {createTestProvider} from '../../../../test/testUtils/TestProvider' @@ -11,12 +11,12 @@ import {ErrorBoundary} from '../ErrorBoundary' describe('ErrorBoundary', () => { beforeAll(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) it('calls onUncaughtError when an error is caught', async () => { - const onUncaughtError = jest.fn() - const onCatch = jest.fn() + const onUncaughtError = vi.fn() + const onCatch = vi.fn() const ThrowErrorComponent = () => { throw new Error('An EXPECTED, testing error occurred!') @@ -46,7 +46,7 @@ describe('ErrorBoundary', () => { }) it('calls onCatch prop when an error is caught when no onUncaughtError exists', () => { - const onCatch = jest.fn() + const onCatch = vi.fn() const WrapperWithoutError = ({children}: {children: React.ReactNode}) => { const locales = [usEnglishLocale]