From 553f124de313b5cc4aabf555579c32c1cda6e651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Tue, 15 Oct 2024 15:29:33 +0200 Subject: [PATCH] test(sanity): migrate tests to vitest --- .../core/preview/utils/replayLatest.test.ts | 2 +- .../__tests__/ReleasesMenu.test.tsx | 30 +++++----- .../__tests__/ReleaseDetailsDialog.test.tsx | 49 ++++++++------- .../dialog/__tests__/ReleaseForm.test.tsx | 26 ++++---- .../ReleaseIconEditorPicker.test.tsx | 13 ++-- .../__tests__/useDocumentVersions.test.tsx | 32 +++++----- .../__tests__/ReleaseMenuButton.test.tsx | 23 +++---- .../detail/__tests__/ReleaseDetail.test.tsx | 60 ++++++++++--------- .../detail/__tests__/ReleaseReview.test.tsx | 33 ++++------ .../detail/__tests__/ReleaseSummary.test.tsx | 35 ++++------- .../__tests__/ReleasesOverview.test.tsx | 40 +++++++------ .../src/core/releases/util/util.test.ts | 2 +- .../utils/fetchFeatureToggle.test.ts | 3 +- .../__tests__/resolvePerspectives.test.ts | 2 +- .../structureTool/StructureTitle.test.tsx | 15 ++--- .../__tests__/DeletedDocumentBanners.test.tsx | 30 +++++----- .../__tests__/DocumentHeaderTitle.test.tsx | 37 +++++------- .../DocumentPerspectiveMenu.test.tsx | 39 ++++++------ .../__tests__/PaneContainer.test.tsx | 16 +++-- .../__tests__/DocumentSheetListPane.test.tsx | 4 +- .../__tests__/useDocumentSheetColumns.test.ts | 4 +- 21 files changed, 235 insertions(+), 260 deletions(-) diff --git a/packages/sanity/src/core/preview/utils/replayLatest.test.ts b/packages/sanity/src/core/preview/utils/replayLatest.test.ts index 03796d77b38..5b0b52f3f21 100644 --- a/packages/sanity/src/core/preview/utils/replayLatest.test.ts +++ b/packages/sanity/src/core/preview/utils/replayLatest.test.ts @@ -1,6 +1,6 @@ -import {expect, test} from '@jest/globals' import {concat, from, lastValueFrom, of, share, timer} from 'rxjs' import {concatMap, delay, mergeMap, take, toArray} from 'rxjs/operators' +import {expect, test} from 'vitest' import {shareReplayLatest} from './shareReplayLatest' diff --git a/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx b/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx index 27a8816fb9e..5e98b37808b 100644 --- a/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx +++ b/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx @@ -1,8 +1,8 @@ -import {beforeEach, describe, expect, it, jest} from '@jest/globals' import {fireEvent, render, screen, within} from '@testing-library/react' import userEvent from '@testing-library/user-event' import {act} from 'react' import {type BundleDocument, useBundles} from 'sanity' +import {beforeEach, describe, expect, it, vi} from 'vitest' import {createTestProvider} from '../../../../../test/testUtils/TestProvider' import {Button} from '../../../../ui-components' @@ -10,25 +10,25 @@ import {usePerspective} from '../../hooks/usePerspective' import {LATEST} from '../../util/const' import {ReleasesMenu} from '../ReleasesMenu' -jest.mock('../../hooks/usePerspective', () => ({ - usePerspective: jest.fn().mockReturnValue({ +vi.mock('../../hooks/usePerspective', () => ({ + usePerspective: vi.fn().mockReturnValue({ currentGlobalBundle: {}, - setPerspective: jest.fn(), + setPerspective: vi.fn(), }), })) -jest.mock('../../util/util', () => ({ - isDraftOrPublished: jest.fn(), +vi.mock('../../util/util', () => ({ + isDraftOrPublished: vi.fn(), })) -jest.mock('../../../store/bundles/useBundles', () => ({ - useBundles: jest.fn().mockReturnValue({deletedBundles: {}}), +vi.mock('../../../store/bundles/useBundles', () => ({ + useBundles: vi.fn().mockReturnValue({deletedBundles: {}}), })) -const mockUseBundles = useBundles as jest.Mock +const mockUseBundles = useBundles as Mock describe('ReleasesMenu', () => { - const mockUsePerspective = usePerspective as jest.Mock + const mockUsePerspective = usePerspective as Mock const ButtonTest =