From d78d42a0ed24b59f4cd00defafa117b2effac041 Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Fri, 2 Oct 2026 10:36:49 -0400 Subject: [PATCH] Share the vue-i18n test mock and let Vitest reset mocks, stubs and env (#5027) --- frontend/__mocks__/vue-i18n.ts | 3 + frontend/src/services/api/save.test.ts | 7 +-- frontend/src/services/api/streaming.test.ts | 13 +---- frontend/src/services/cache/api.test.ts | 1 - frontend/src/services/native.test.ts | 1 - frontend/src/services/pending-asset.test.ts | 11 ---- frontend/src/stores/native.test.ts | 5 -- frontend/src/test-utils/resizeObserver.ts | 2 +- .../src/v2/components/AppShell/AppNav.test.ts | 4 +- .../AppShell/BackendStatusBanner.test.ts | 6 +- .../src/v2/components/Auth/ResetForm.test.ts | 4 +- .../Collections/CollectionTile.test.ts | 4 +- .../v2/components/Dialogs/AboutDialog.test.ts | 4 +- .../Dialogs/CopyDownloadLinkDialog.test.ts | 4 +- .../Dialogs/DeleteRomDialog.test.ts | 6 +- .../Dialogs/InstallOnDeviceDialog.test.ts | 7 +-- .../Dialogs/ManageCollectionsDialog.test.ts | 6 +- .../Dialogs/ManualUploadTargetDialog.test.ts | 10 +--- .../components/Dialogs/MatchRomDialog.test.ts | 10 +--- .../Dialogs/RefreshMetadataDialog.test.ts | 5 +- .../Dialogs/SearchCoverDialog.test.ts | 5 +- .../components/Gallery/AlphaJumpMenu.test.ts | 4 +- .../Gallery/BackToTopButton.test.ts | 4 +- .../Gallery/CollectionSettingsTab.test.ts | 1 - .../components/Gallery/GalleryToolbar.test.ts | 4 +- .../components/Gallery/GameListHeader.test.ts | 4 +- .../components/Gallery/SelectionBar.test.ts | 16 +---- .../v2/components/Gallery/SettingsTab.test.ts | 6 +- .../GameActions/GameActionBtn.test.ts | 5 +- .../GameActions/GameActionsList.test.ts | 4 +- .../v2/components/GameCard/GameCard.test.ts | 4 +- .../GameDetails/AssetEditDialog.test.ts | 4 +- .../GameDetails/FilesTab/FilesTab.test.ts | 12 +--- .../FilesTab/UploadFilesDialog.test.ts | 4 +- .../components/GameDetails/GameHeader.test.ts | 4 +- .../components/GameDetails/MediaTab.test.ts | 4 +- .../GameDetails/MetadataTab.test.ts | 4 +- .../GameDetails/OverviewTab.test.ts | 4 +- .../components/GameDetails/PatcherTab.test.ts | 5 +- .../components/GameDetails/PdfViewer.test.ts | 10 +--- .../GameDetails/PrevNextNav.test.ts | 4 +- .../GameDetails/SaveDataTab.test.ts | 4 +- .../GameDetails/ScreenshotEditDialog.test.ts | 4 +- .../components/GameDetails/SubtabNav.test.ts | 4 +- .../GameDetails/UploadAssetDialog.test.ts | 4 +- .../Home/Widgets/AnniversaryWidget.test.ts | 1 - .../Home/Widgets/RandomPickWidget.test.ts | 10 +--- .../MatchRom/MatchRomRenameToggle.test.ts | 4 +- .../NotificationChannelsSection.test.ts | 4 +- .../Notifications/NotificationInbox.test.ts | 4 +- .../SendNotificationSection.test.ts | 4 +- .../v2/components/Player/AssetPreview.test.ts | 4 +- .../Player/LoadSaveStateDialog.test.ts | 10 +--- .../Player/MemoryCardDialog.test.ts | 4 +- .../Player/MemoryCardManager.test.ts | 5 +- .../v2/components/Player/PlayerShell.test.ts | 4 +- .../Player/SessionEndedReason.test.ts | 4 +- .../v2/components/Scan/ScanPlatform.test.ts | 4 +- .../components/Scan/ScanPlatformRow.test.ts | 4 +- .../Scan/ScanProviderSelect.test.ts | 4 +- .../Settings/FolderMappingsSection.test.ts | 4 +- .../Settings/HiddenGamesPicker.test.ts | 4 +- .../Settings/PlatformsStatsSection.test.ts | 6 +- .../Settings/ScanPriorityList.test.ts | 4 +- .../v2/components/shared/AssetActions.test.ts | 4 +- .../v2/components/shared/AssetChips.test.ts | 4 +- .../components/shared/ConfirmDialog.test.ts | 10 +--- .../v2/components/shared/LocationChip.test.ts | 4 +- .../shared/VisibilitySwitch.test.ts | 4 +- .../components/shared/platformSelect.test.ts | 4 +- .../v2/composables/useCanPlay/index.test.ts | 6 -- .../v2/composables/useClipboard/index.test.ts | 12 +--- .../composables/useCoverFilters/index.test.ts | 4 +- .../useGallerySelectAll/index.test.ts | 15 +---- .../composables/useGameActions/index.test.ts | 9 +-- .../v2/composables/useGamepad/index.test.ts | 2 - .../useGlobalHotkeys/index.test.ts | 1 - .../useIsolatedLaunch/index.test.ts | 45 +++----------- .../useJoinStreamConfirm/index.test.ts | 11 +--- .../composables/useMediaSession/index.test.ts | 1 - .../composables/useNativeLaunch/index.test.ts | 9 --- .../usePendingAssetSync/index.test.ts | 9 +-- .../composables/usePinnedMedia/index.test.ts | 29 ++++------ .../composables/usePlayerExit/index.test.ts | 41 ++----------- .../usePlayerFullscreen/index.test.ts | 1 - .../useReducedMotion/index.test.ts | 37 +++++------- .../useResponsiveColumns/index.test.ts | 3 +- .../useRomFileUpload/index.test.ts | 5 +- .../useRomScanRefresh/index.test.ts | 1 - .../useScanLifecycle/index.test.ts | 5 +- .../useScanProviders/index.test.ts | 4 +- .../composables/useScanTrigger/index.test.ts | 12 +--- .../useServerConnection/index.test.ts | 29 +--------- .../composables/useSpatialNav/index.test.ts | 2 - .../composables/useTrackPager/index.test.ts | 3 +- .../useViewTransition/index.test.ts | 3 +- .../composables/useWrapGridNav/index.test.ts | 1 - frontend/src/v2/layouts/AuthLayout.test.ts | 4 +- .../RComboboxField/RComboboxField.test.ts | 1 - .../src/v2/lib/forms/RSelect/RSelect.test.ts | 1 - .../lib/forms/RTextField/RTextField.test.ts | 6 +- frontend/src/v2/stores/galleryRoms.test.ts | 14 +---- .../v2/utils/metadataProviderGroups.test.ts | 4 +- frontend/src/v2/utils/pico8Audio.test.ts | 1 - frontend/src/v2/utils/pico8Input.test.ts | 6 +- frontend/src/v2/utils/pico8Runtime.test.ts | 1 - .../src/v2/views/CollectionsIndex.test.ts | 4 +- .../src/v2/views/Gallery/Collection.test.ts | 10 +--- .../src/v2/views/Gallery/Platform.test.ts | 5 +- .../src/v2/views/Jukebox/BrowseMode.test.ts | 4 +- frontend/src/v2/views/Notifications.test.ts | 4 +- frontend/src/v2/views/PlatformsIndex.test.ts | 4 +- frontend/src/v2/views/Player/Desktop.test.ts | 6 +- frontend/src/v2/views/Player/JsDos.test.ts | 58 ++++--------------- frontend/src/v2/views/Player/Ruffle.test.ts | 21 +------ frontend/src/v2/views/Player/Stream.test.ts | 8 --- .../src/v2/views/Player/jsDosRuntime.test.ts | 17 +----- .../views/Settings/ConversionSettings.test.ts | 4 +- frontend/src/v2/views/Settings/Logs.test.ts | 4 +- .../v2/views/Settings/MetadataSources.test.ts | 4 +- frontend/src/v2/views/Upload.test.ts | 6 +- frontend/vitest.config.ts | 6 ++ 122 files changed, 171 insertions(+), 691 deletions(-) create mode 100644 frontend/__mocks__/vue-i18n.ts diff --git a/frontend/__mocks__/vue-i18n.ts b/frontend/__mocks__/vue-i18n.ts new file mode 100644 index 000000000..217c5a107 --- /dev/null +++ b/frontend/__mocks__/vue-i18n.ts @@ -0,0 +1,3 @@ +// Used by `vi.mock("vue-i18n")` with no factory: `t` echoes the key, so tests +// assert on which message a component asked for rather than its wording. +export const useI18n = () => ({ t: (key: string) => key }); diff --git a/frontend/src/services/api/save.test.ts b/frontend/src/services/api/save.test.ts index f47eb3e57..5b626e5bb 100644 --- a/frontend/src/services/api/save.test.ts +++ b/frontend/src/services/api/save.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import type { DetailedRomSchema } from "@/__generated__"; import saveApi, { UNLOAD_SAVE_MAX_BYTES } from "@/services/api/save"; import { saveFixture } from "@/utils/assets.fixtures"; @@ -35,11 +35,6 @@ describe("sendSaveOnUnload", () => { document.cookie = "romm_csrftoken=token"; }); - afterEach(() => { - vi.unstubAllGlobals(); - fetchMock.mockClear(); - }); - it("opens a version with a keepalive request the page does not wait for", () => { const sent = saveApi.sendSaveOnUnload({ rom, diff --git a/frontend/src/services/api/streaming.test.ts b/frontend/src/services/api/streaming.test.ts index ced0361bd..7163c332b 100644 --- a/frontend/src/services/api/streaming.test.ts +++ b/frontend/src/services/api/streaming.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import streamingApi from "@/services/api/streaming"; const post = vi.hoisted(() => vi.fn()); @@ -15,12 +15,6 @@ describe("releaseSessionKeepalive", () => { vi.stubGlobal("fetch", fetchMock); }); - afterEach(() => { - vi.unstubAllGlobals(); - vi.restoreAllMocks(); - fetchMock.mockClear(); - }); - it("names the container and the claim where URLSearchParams has no size", async () => { // Chrome 111-112 and Safari 16.4 are in .browserslistrc and predate it. vi.spyOn(URLSearchParams.prototype, "size", "get").mockReturnValue( @@ -52,11 +46,6 @@ describe("saveAndExitKeepalive", () => { vi.stubGlobal("fetch", fetchMock); }); - afterEach(() => { - vi.unstubAllGlobals(); - fetchMock.mockClear(); - }); - it("names the container and the claim it saves", async () => { await streamingApi.saveAndExitKeepalive( "ps2", diff --git a/frontend/src/services/cache/api.test.ts b/frontend/src/services/cache/api.test.ts index 33fe81424..2868380d1 100644 --- a/frontend/src/services/cache/api.test.ts +++ b/frontend/src/services/cache/api.test.ts @@ -34,7 +34,6 @@ function clearedPattern(callIndex = 0): string { } beforeEach(() => { - vi.clearAllMocks(); vi.mocked(cacheService.request).mockResolvedValue({ data: { items: [] }, } as AxiosResponse); diff --git a/frontend/src/services/native.test.ts b/frontend/src/services/native.test.ts index 147f2d46b..1b2fd43f7 100644 --- a/frontend/src/services/native.test.ts +++ b/frontend/src/services/native.test.ts @@ -37,7 +37,6 @@ function installBridge(bridge: Partial): void { beforeEach(() => { delete window.rommNative; - vi.restoreAllMocks(); vi.spyOn(console, "error").mockImplementation(() => {}); }); diff --git a/frontend/src/services/pending-asset.test.ts b/frontend/src/services/pending-asset.test.ts index 87575c72f..0e04fdb5e 100644 --- a/frontend/src/services/pending-asset.test.ts +++ b/frontend/src/services/pending-asset.test.ts @@ -33,10 +33,6 @@ describe("pendingAssetStore without IndexedDB", () => { vi.spyOn(console, "error").mockImplementation(() => undefined); }); - afterEach(() => { - vi.restoreAllMocks(); - }); - // A private window looks the same: the player must hear nothing was kept. it("says a write kept nothing rather than throwing", async () => { await expect( @@ -69,10 +65,6 @@ describe("pendingAssetStore without IndexedDB", () => { }); describe("pendingAssetId", () => { - afterEach(() => { - vi.unstubAllGlobals(); - }); - it("keys a capture to its rom", () => { expect(pendingAssetId(7)).toMatch(/^7:.+/); }); @@ -236,9 +228,6 @@ describe("syncPendingAssets", () => { }); afterEach(() => { - vi.unstubAllGlobals(); - vi.unstubAllEnvs(); - vi.restoreAllMocks(); romApiMocks.getRom.mockReset(); saveApiMocks.uploadSaves.mockReset(); stateApiMocks.uploadStates.mockReset(); diff --git a/frontend/src/stores/native.test.ts b/frontend/src/stores/native.test.ts index 319936a23..7abc8b74a 100644 --- a/frontend/src/stores/native.test.ts +++ b/frontend/src/stores/native.test.ts @@ -93,17 +93,12 @@ function makeRom(overrides: Partial = {}): SimpleRom { beforeEach(() => { shellPresent.value = true; emit = null; - fetchPlatformSupport.mockClear(); fetchPlatformSupport.mockResolvedValue({}); - launchNative.mockClear(); launchNative.mockResolvedValue({ romId: 1, emulator: "RetroArch" }); - cancelNative.mockClear(); cancelNative.mockResolvedValue(true); - getRom.mockClear(); getRom.mockResolvedValue({ data: { files: [{ full_path: "psx/disc.chd", file_size_bytes: 700 }] }, }); - unsubscribe.mockClear(); soleFile.value = { full_path: "snes/game.sfc", file_size_bytes: 4194304 }; }); diff --git a/frontend/src/test-utils/resizeObserver.ts b/frontend/src/test-utils/resizeObserver.ts index 154a936f9..20dd922ce 100644 --- a/frontend/src/test-utils/resizeObserver.ts +++ b/frontend/src/test-utils/resizeObserver.ts @@ -46,7 +46,7 @@ function boxSize({ width, height }: Size): ResizeObserverSize[] { return [{ inlineSize: width, blockSize: height }]; } -/** Installs the fake for the current test; undo with `vi.unstubAllGlobals()`. */ +/** Installs the fake for the current test; `unstubGlobals` removes it before the next one. */ export function stubResizeObserver() { FakeResizeObserver.instances.clear(); vi.stubGlobal("ResizeObserver", FakeResizeObserver); diff --git a/frontend/src/v2/components/AppShell/AppNav.test.ts b/frontend/src/v2/components/AppShell/AppNav.test.ts index 745cf1aa8..0b92aca90 100644 --- a/frontend/src/v2/components/AppShell/AppNav.test.ts +++ b/frontend/src/v2/components/AppShell/AppNav.test.ts @@ -3,9 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { computed, nextTick, ref } from "vue"; import AppNav from "./AppNav.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useNavDestinations", () => ({ useNavDestinations: () => ({ diff --git a/frontend/src/v2/components/AppShell/BackendStatusBanner.test.ts b/frontend/src/v2/components/AppShell/BackendStatusBanner.test.ts index 27b2f75c5..5dcd71e14 100644 --- a/frontend/src/v2/components/AppShell/BackendStatusBanner.test.ts +++ b/frontend/src/v2/components/AppShell/BackendStatusBanner.test.ts @@ -4,9 +4,7 @@ import { ref } from "vue"; import storePlaying from "@/stores/playing"; import BackendStatusBanner from "./BackendStatusBanner.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const isOffline = ref(false); const isWebSocketDegraded = ref(false); @@ -46,8 +44,6 @@ describe("BackendStatusBanner", () => { vi.useFakeTimers(); isOffline.value = false; isWebSocketDegraded.value = false; - retryNow.mockClear(); - retryWebSocket.mockClear(); }); afterEach(() => { diff --git a/frontend/src/v2/components/Auth/ResetForm.test.ts b/frontend/src/v2/components/Auth/ResetForm.test.ts index 417476767..ce46a8603 100644 --- a/frontend/src/v2/components/Auth/ResetForm.test.ts +++ b/frontend/src/v2/components/Auth/ResetForm.test.ts @@ -11,9 +11,7 @@ const { requestPasswordReset, success } = vi.hoisted(() => ({ vi.mock("@/services/api/identity", () => ({ default: { requestPasswordReset }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useSnackbar", async (importOriginal) => ({ ...(await importOriginal()), useSnackbar: () => ({ success, error: vi.fn() }), diff --git a/frontend/src/v2/components/Collections/CollectionTile.test.ts b/frontend/src/v2/components/Collections/CollectionTile.test.ts index 98e48bbdc..86cd8b5dd 100644 --- a/frontend/src/v2/components/Collections/CollectionTile.test.ts +++ b/frontend/src/v2/components/Collections/CollectionTile.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import CollectionTile from "./CollectionTile.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", async (importOriginal) => ({ ...(await importOriginal()), useRouter: () => ({ push: vi.fn() }), diff --git a/frontend/src/v2/components/Dialogs/AboutDialog.test.ts b/frontend/src/v2/components/Dialogs/AboutDialog.test.ts index 30cbc2779..f58a342e2 100644 --- a/frontend/src/v2/components/Dialogs/AboutDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/AboutDialog.test.ts @@ -8,9 +8,7 @@ import storeHeartbeat from "@/stores/heartbeat"; import type { Events } from "@/types/emitter"; import AboutDialog from "./AboutDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); // happy-dom has no ResizeObserver that fires, so the test lays the grid out. const resize = vi.hoisted(() => ({ layout: () => {} })); diff --git a/frontend/src/v2/components/Dialogs/CopyDownloadLinkDialog.test.ts b/frontend/src/v2/components/Dialogs/CopyDownloadLinkDialog.test.ts index 8cda76f26..e61608e47 100644 --- a/frontend/src/v2/components/Dialogs/CopyDownloadLinkDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/CopyDownloadLinkDialog.test.ts @@ -6,9 +6,7 @@ import CopyDownloadLinkDialog from "./CopyDownloadLinkDialog.vue"; const { copy } = vi.hoisted(() => ({ copy: vi.fn() })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useClipboard", () => ({ useClipboard: () => ({ isSupported: true, copy }), diff --git a/frontend/src/v2/components/Dialogs/DeleteRomDialog.test.ts b/frontend/src/v2/components/Dialogs/DeleteRomDialog.test.ts index f059708c5..ce2d30e1f 100644 --- a/frontend/src/v2/components/Dialogs/DeleteRomDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/DeleteRomDialog.test.ts @@ -18,9 +18,7 @@ const route = reactive<{ name: string; params: Record }>({ params: { rom: "5" }, }); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", async (importOriginal) => ({ ...(await importOriginal()), useRoute: () => route, @@ -87,7 +85,6 @@ async function deleteShownGame() { describe("DeleteRomDialog", () => { beforeEach(() => { - vi.clearAllMocks(); route.name = "rom"; route.params = { rom: "5" }; deleteRoms.mockResolvedValue({ @@ -124,7 +121,6 @@ describe("DeleteRomDialog", () => { describe("DeleteRomDialog with a large selection", () => { beforeEach(() => { - vi.clearAllMocks(); deleteRoms.mockResolvedValue({ data: { failed_ids: [], successful_items: 120 }, }); diff --git a/frontend/src/v2/components/Dialogs/InstallOnDeviceDialog.test.ts b/frontend/src/v2/components/Dialogs/InstallOnDeviceDialog.test.ts index 77b4b9589..7fa76cb3b 100644 --- a/frontend/src/v2/components/Dialogs/InstallOnDeviceDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/InstallOnDeviceDialog.test.ts @@ -23,11 +23,7 @@ const { socketHandlers: new Map void>(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ - t: (key: string) => key, - }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/device", () => ({ default: { fetchDevices, fetchOnlineDeviceIds }, @@ -131,7 +127,6 @@ async function toggle(wrapper: VueWrapper, checked: boolean) { describe("InstallOnDeviceDialog", () => { beforeEach(() => { vi.useFakeTimers(); - vi.clearAllMocks(); socketHandlers.clear(); fetchOnlineDeviceIds.mockResolvedValue({ data: [] }); fetchRomInstalls.mockResolvedValue({ data: [] }); diff --git a/frontend/src/v2/components/Dialogs/ManageCollectionsDialog.test.ts b/frontend/src/v2/components/Dialogs/ManageCollectionsDialog.test.ts index 699501cd5..75076927e 100644 --- a/frontend/src/v2/components/Dialogs/ManageCollectionsDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/ManageCollectionsDialog.test.ts @@ -24,9 +24,7 @@ const { snackbarError: vi.fn(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/collection", () => ({ default: { @@ -119,7 +117,6 @@ function mountDialog( describe("ManageCollectionsDialog gallery reconcile", () => { beforeEach(() => { - vi.clearAllMocks(); storeAuth().setCurrentUser({ id: USER_ID } as User); }); @@ -218,7 +215,6 @@ describe("ManageCollectionsDialog gallery reconcile", () => { describe("ManageCollectionsDialog create", () => { beforeEach(() => { - vi.clearAllMocks(); storeAuth().setCurrentUser(userFixture({ id: USER_ID })); }); diff --git a/frontend/src/v2/components/Dialogs/ManualUploadTargetDialog.test.ts b/frontend/src/v2/components/Dialogs/ManualUploadTargetDialog.test.ts index aa8dedd66..04d5ba95c 100644 --- a/frontend/src/v2/components/Dialogs/ManualUploadTargetDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/ManualUploadTargetDialog.test.ts @@ -1,6 +1,6 @@ import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; import mitt, { type Emitter } from "mitt"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import type { DetailedRom } from "@/stores/roms"; import type { Events } from "@/types/emitter"; import ManualUploadTargetDialog from "./ManualUploadTargetDialog.vue"; @@ -15,9 +15,7 @@ const { uploadManuals, uploadFiles, getRom } = vi.hoisted(() => ({ getRom: vi.fn(() => Promise.resolve({ data: {} })), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/rom", () => ({ default: { uploadManuals, getRom }, @@ -104,10 +102,6 @@ async function upload(target: DetailedRom): Promise { } describe("ManualUploadTargetDialog", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("sends a single-file ROM's manual to resources without asking", async () => { const wrapper = await upload(rom({ has_simple_single_file: true })); diff --git a/frontend/src/v2/components/Dialogs/MatchRomDialog.test.ts b/frontend/src/v2/components/Dialogs/MatchRomDialog.test.ts index 11d34a65e..8b2ab6e49 100644 --- a/frontend/src/v2/components/Dialogs/MatchRomDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/MatchRomDialog.test.ts @@ -1,6 +1,6 @@ import { flushPromises, mount } from "@vue/test-utils"; import mitt, { type Emitter } from "mitt"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { ref } from "vue"; import type { SearchRom, SimpleRom } from "@/stores/roms"; import type { Events } from "@/types/emitter"; @@ -8,9 +8,7 @@ import MatchRomDialog from "./MatchRomDialog.vue"; const { searchRom } = vi.hoisted(() => ({ searchRom: vi.fn() })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", async (importOriginal) => ({ ...(await importOriginal()), useRoute: () => ({ name: "gallery" }), @@ -70,10 +68,6 @@ function match(overrides: Partial = {}): SearchRom { } describe("MatchRomDialog", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("drops a search left running when the dialog closes", async () => { let finishStale: (value: { data: SearchRom[] }) => void = () => {}; searchRom diff --git a/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.test.ts b/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.test.ts index 3120be600..cb52a308d 100644 --- a/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.test.ts @@ -14,9 +14,7 @@ const { startScan, persistSelection, snackbarInfo, sources } = vi.hoisted( }), ); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useScanTrigger", () => ({ useScanTrigger: () => ({ startScan }), })); @@ -109,7 +107,6 @@ function scanButton(wrapper: Awaited>) { describe("RefreshMetadataDialog", () => { beforeEach(() => { - vi.clearAllMocks(); startScan.mockReturnValue(true); sources.value = []; }); diff --git a/frontend/src/v2/components/Dialogs/SearchCoverDialog.test.ts b/frontend/src/v2/components/Dialogs/SearchCoverDialog.test.ts index 50f85a374..9a560b37d 100644 --- a/frontend/src/v2/components/Dialogs/SearchCoverDialog.test.ts +++ b/frontend/src/v2/components/Dialogs/SearchCoverDialog.test.ts @@ -23,9 +23,7 @@ const { searchCover, searchRom, heartbeat } = vi.hoisted(() => ({ }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/sgdb", () => ({ default: { searchCover } })); vi.mock("@/services/api/rom", () => ({ default: { searchRom } })); vi.mock("@/stores/heartbeat", () => ({ default: () => heartbeat })); @@ -129,7 +127,6 @@ function gridThumbs( describe("SearchCoverDialog", () => { beforeEach(() => { - vi.clearAllMocks(); searchRom.mockResolvedValue({ data: [] }); }); diff --git a/frontend/src/v2/components/Gallery/AlphaJumpMenu.test.ts b/frontend/src/v2/components/Gallery/AlphaJumpMenu.test.ts index 69edc620c..d21f58c91 100644 --- a/frontend/src/v2/components/Gallery/AlphaJumpMenu.test.ts +++ b/frontend/src/v2/components/Gallery/AlphaJumpMenu.test.ts @@ -4,9 +4,7 @@ import { describe, expect, it, vi } from "vitest"; import { defineComponent, h } from "vue"; import AlphaJumpMenu from "./AlphaJumpMenu.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useWrapGridNav", () => ({ useWrapGridNav: vi.fn(), diff --git a/frontend/src/v2/components/Gallery/BackToTopButton.test.ts b/frontend/src/v2/components/Gallery/BackToTopButton.test.ts index 81691056b..b0136f3d5 100644 --- a/frontend/src/v2/components/Gallery/BackToTopButton.test.ts +++ b/frontend/src/v2/components/Gallery/BackToTopButton.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { afterEach, describe, expect, it, vi } from "vitest"; import BackToTopButton from "./BackToTopButton.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const { resized } = vi.hoisted(() => ({ resized: { callback: () => {} } })); vi.mock("@vueuse/core", async (importOriginal) => ({ diff --git a/frontend/src/v2/components/Gallery/CollectionSettingsTab.test.ts b/frontend/src/v2/components/Gallery/CollectionSettingsTab.test.ts index 2b106846a..656975f86 100644 --- a/frontend/src/v2/components/Gallery/CollectionSettingsTab.test.ts +++ b/frontend/src/v2/components/Gallery/CollectionSettingsTab.test.ts @@ -57,7 +57,6 @@ function mountTab() { describe("CollectionSettingsTab visibility", () => { beforeEach(() => { - vi.clearAllMocks(); storeAuth().setCurrentUser( userFixture({ id: 1, oauth_scopes: ["collections.write"] }), ); diff --git a/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts b/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts index 45b74f455..3c62d28cf 100644 --- a/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts +++ b/frontend/src/v2/components/Gallery/GalleryToolbar.test.ts @@ -3,9 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { ref } from "vue"; import GalleryToolbar from "./GalleryToolbar.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const smAndUp = ref(true); vi.mock("@/v2/composables/useBreakpoint", () => ({ diff --git a/frontend/src/v2/components/Gallery/GameListHeader.test.ts b/frontend/src/v2/components/Gallery/GameListHeader.test.ts index af118125d..f935b2f81 100644 --- a/frontend/src/v2/components/Gallery/GameListHeader.test.ts +++ b/frontend/src/v2/components/Gallery/GameListHeader.test.ts @@ -3,9 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { ref } from "vue"; import GameListHeader from "./GameListHeader.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const smAndDown = ref(false); vi.mock("@/v2/composables/useBreakpoint", () => ({ diff --git a/frontend/src/v2/components/Gallery/SelectionBar.test.ts b/frontend/src/v2/components/Gallery/SelectionBar.test.ts index ee40a121c..b49ce5de8 100644 --- a/frontend/src/v2/components/Gallery/SelectionBar.test.ts +++ b/frontend/src/v2/components/Gallery/SelectionBar.test.ts @@ -1,5 +1,5 @@ import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { nextTick, ref } from "vue"; import storeAuth from "@/stores/auth"; import storeCollections, { type Collection } from "@/stores/collections"; @@ -155,7 +155,6 @@ async function clickHeart(wrapper: VueWrapper) { describe("SelectionBar bulk favorite", () => { beforeEach(() => { storeAuth().setCurrentUser(userFixture()); - vi.clearAllMocks(); }); it("creates the favourites collection when the instance has none", async () => { @@ -295,10 +294,6 @@ describe("SelectionBar bulk favorite", () => { }); describe("SelectionBar download", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("offers the download action by default", () => { select(rom(1)); @@ -321,10 +316,6 @@ describe("SelectionBar download", () => { }); describe("SelectionBar select all", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("triggers the whole-result select-all", async () => { select(rom(1)); const wrapper = mountBar(); @@ -350,10 +341,6 @@ describe("SelectionBar select all", () => { }); describe("SelectionBar bulk status", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("ignores a status choice while the previous batch is running", async () => { let finish: () => void = () => {}; updateUserRomProps.mockImplementation( @@ -390,7 +377,6 @@ describe("SelectionBar outline", () => { beforeEach(() => { storeAuth().setCurrentUser(userFixture()); }); - afterEach(() => vi.unstubAllGlobals()); it("draws the outline from the bar's and notch's measured sizes", async () => { const observer = stubResizeObserver(); diff --git a/frontend/src/v2/components/Gallery/SettingsTab.test.ts b/frontend/src/v2/components/Gallery/SettingsTab.test.ts index 36028a950..fcc460997 100644 --- a/frontend/src/v2/components/Gallery/SettingsTab.test.ts +++ b/frontend/src/v2/components/Gallery/SettingsTab.test.ts @@ -1,5 +1,5 @@ import { flushPromises, mount } from "@vue/test-utils"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import type { Platform } from "@/stores/platforms"; import SettingsTab from "./SettingsTab.vue"; @@ -81,10 +81,6 @@ function mountTab(p: Platform) { } describe("SettingsTab platform save", () => { - beforeEach(() => { - updatePlatform.mockClear(); - }); - it("does not stamp custom_name when only the description changed", async () => { updatePlatform.mockResolvedValue({ data: platform() }); const p = platform(); diff --git a/frontend/src/v2/components/GameActions/GameActionBtn.test.ts b/frontend/src/v2/components/GameActions/GameActionBtn.test.ts index 7ea47e842..a66c2ea25 100644 --- a/frontend/src/v2/components/GameActions/GameActionBtn.test.ts +++ b/frontend/src/v2/components/GameActions/GameActionBtn.test.ts @@ -7,9 +7,7 @@ import GameActionBtn from "./GameActionBtn.vue"; const play = vi.fn(); const needsLaunchConfirm = { value: false }; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useBreakpoint", () => ({ useBreakpoint: () => ({ smAndDown: ref(false) }), @@ -56,7 +54,6 @@ function click(el: Element, init: MouseEventInit = {}): boolean { } beforeEach(() => { - play.mockClear(); needsLaunchConfirm.value = false; }); diff --git a/frontend/src/v2/components/GameActions/GameActionsList.test.ts b/frontend/src/v2/components/GameActions/GameActionsList.test.ts index faf972506..813cd68b8 100644 --- a/frontend/src/v2/components/GameActions/GameActionsList.test.ts +++ b/frontend/src/v2/components/GameActions/GameActionsList.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import type { SimpleRom } from "@/stores/roms"; import GameActionsList from "./GameActionsList.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); type Flags = { canPlayLocally: boolean; diff --git a/frontend/src/v2/components/GameCard/GameCard.test.ts b/frontend/src/v2/components/GameCard/GameCard.test.ts index 2a8cbeb1b..4a07d5e59 100644 --- a/frontend/src/v2/components/GameCard/GameCard.test.ts +++ b/frontend/src/v2/components/GameCard/GameCard.test.ts @@ -5,9 +5,7 @@ import type { SimpleRom } from "@/stores/roms"; import storeGallerySelection from "@/v2/stores/gallerySelection"; import GameCard from "./GameCard.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); function rom(id: number): SimpleRom { return { id, name: `Game ${id}`, platform_slug: "snes" } as SimpleRom; diff --git a/frontend/src/v2/components/GameDetails/AssetEditDialog.test.ts b/frontend/src/v2/components/GameDetails/AssetEditDialog.test.ts index 54a32caa1..b13dcec27 100644 --- a/frontend/src/v2/components/GameDetails/AssetEditDialog.test.ts +++ b/frontend/src/v2/components/GameDetails/AssetEditDialog.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import AssetEditDialog from "./AssetEditDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/locales", () => ({ default: { global: { t: (key: string) => key } }, })); diff --git a/frontend/src/v2/components/GameDetails/FilesTab/FilesTab.test.ts b/frontend/src/v2/components/GameDetails/FilesTab/FilesTab.test.ts index cf5f37da7..fc37c8ccd 100644 --- a/frontend/src/v2/components/GameDetails/FilesTab/FilesTab.test.ts +++ b/frontend/src/v2/components/GameDetails/FilesTab/FilesTab.test.ts @@ -26,9 +26,7 @@ const { grants: { upload: true, delete: false }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", async (importOriginal) => ({ ...(await importOriginal()), useRoute: () => ({ query: routeQuery, path: "/rom/1", params: {} }), @@ -141,7 +139,6 @@ async function pickFile(wrapper: ReturnType, name: string) { describe("FilesTab uploads", () => { beforeEach(() => { - vi.clearAllMocks(); routeQuery.subtab = undefined; grants.upload = true; uploadRoms.mockResolvedValue([{ status: "fulfilled", value: null }]); @@ -250,7 +247,6 @@ describe("FilesTab uploads", () => { describe("FilesTab on a rom missing from the filesystem", () => { beforeEach(() => { - vi.clearAllMocks(); routeQuery.subtab = undefined; grants.upload = true; }); @@ -283,7 +279,6 @@ describe("FilesTab on a rom missing from the filesystem", () => { describe("FilesTab selection", () => { beforeEach(() => { - vi.clearAllMocks(); routeQuery.subtab = undefined; grants.upload = true; }); @@ -329,10 +324,7 @@ describe("FilesTab copy link", () => { writeText: ((text: string) => Promise) | null, secure = true, ) { - Object.defineProperty(window, "isSecureContext", { - configurable: true, - value: secure, - }); + vi.stubGlobal("isSecureContext", secure); Object.defineProperty(navigator, "clipboard", { configurable: true, value: writeText ? { writeText } : undefined, diff --git a/frontend/src/v2/components/GameDetails/FilesTab/UploadFilesDialog.test.ts b/frontend/src/v2/components/GameDetails/FilesTab/UploadFilesDialog.test.ts index 33e215447..1d021618f 100644 --- a/frontend/src/v2/components/GameDetails/FilesTab/UploadFilesDialog.test.ts +++ b/frontend/src/v2/components/GameDetails/FilesTab/UploadFilesDialog.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import { nextTick } from "vue"; import UploadFilesDialog from "./UploadFilesDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/locales", () => ({ default: { global: { t: (key: string) => key } }, })); diff --git a/frontend/src/v2/components/GameDetails/GameHeader.test.ts b/frontend/src/v2/components/GameDetails/GameHeader.test.ts index 6cabaae72..ccbb8118c 100644 --- a/frontend/src/v2/components/GameDetails/GameHeader.test.ts +++ b/frontend/src/v2/components/GameDetails/GameHeader.test.ts @@ -9,9 +9,7 @@ const { showLogoTitle, xs } = vi.hoisted(() => ({ xs: { value: false }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/composables/useUISettings", () => ({ useUISettings: () => ({ showLogoTitle }), diff --git a/frontend/src/v2/components/GameDetails/MediaTab.test.ts b/frontend/src/v2/components/GameDetails/MediaTab.test.ts index 9b6392b5e..6aa1ba631 100644 --- a/frontend/src/v2/components/GameDetails/MediaTab.test.ts +++ b/frontend/src/v2/components/GameDetails/MediaTab.test.ts @@ -5,9 +5,7 @@ import { createMemoryHistory, createRouter, type Router } from "vue-router"; import { makeDetailedRom } from "@/utils/rom.fixtures"; import MediaTab from "./MediaTab.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useRomSync", () => ({ useRomSync: () => ({ refetchRom: vi.fn() }), })); diff --git a/frontend/src/v2/components/GameDetails/MetadataTab.test.ts b/frontend/src/v2/components/GameDetails/MetadataTab.test.ts index c38465273..563130761 100644 --- a/frontend/src/v2/components/GameDetails/MetadataTab.test.ts +++ b/frontend/src/v2/components/GameDetails/MetadataTab.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import type { DetailedRom } from "@/stores/roms"; import MetadataTab from "./MetadataTab.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const CRC = "aabbccdd"; const MD5 = "0123456789abcdef0123456789abcdef"; diff --git a/frontend/src/v2/components/GameDetails/OverviewTab.test.ts b/frontend/src/v2/components/GameDetails/OverviewTab.test.ts index 39d0881f8..7bbf128a6 100644 --- a/frontend/src/v2/components/GameDetails/OverviewTab.test.ts +++ b/frontend/src/v2/components/GameDetails/OverviewTab.test.ts @@ -6,9 +6,7 @@ import type { DetailedRom } from "@/stores/roms"; import type { MediaShelfItem } from "./MediaShelf.vue"; import OverviewTab from "./OverviewTab.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const showRecommendations = ref(true); diff --git a/frontend/src/v2/components/GameDetails/PatcherTab.test.ts b/frontend/src/v2/components/GameDetails/PatcherTab.test.ts index 6b4b64ae9..9f2b12a41 100644 --- a/frontend/src/v2/components/GameDetails/PatcherTab.test.ts +++ b/frontend/src/v2/components/GameDetails/PatcherTab.test.ts @@ -5,9 +5,7 @@ import PatcherTab from "./PatcherTab.vue"; const { post } = vi.hoisted(() => ({ post: vi.fn() })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("pinia", async (importOriginal) => ({ ...(await importOriginal()), storeToRefs: (store: object) => store, @@ -103,7 +101,6 @@ function rom(): DetailedRomSchema { describe("PatcherTab", () => { beforeEach(() => { - vi.clearAllMocks(); post.mockResolvedValue({ data: new Blob(["patched"]), headers: {} }); vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => {}); }); diff --git a/frontend/src/v2/components/GameDetails/PdfViewer.test.ts b/frontend/src/v2/components/GameDetails/PdfViewer.test.ts index 4e292dded..8adb1c08a 100644 --- a/frontend/src/v2/components/GameDetails/PdfViewer.test.ts +++ b/frontend/src/v2/components/GameDetails/PdfViewer.test.ts @@ -1,11 +1,9 @@ import { mount } from "@vue/test-utils"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { nextTick, ref } from "vue"; import PdfViewer from "./PdfViewer.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue3-pdf-app", () => ({ default: { name: "VuePdfApp", template: `
` }, })); @@ -36,10 +34,6 @@ beforeEach(() => { ); }); -afterEach(() => { - vi.unstubAllGlobals(); -}); - describe("PdfViewer", () => { it("waits for a laid-out container before loading pdf.js", async () => { const wrapper = mount(PdfViewer, { diff --git a/frontend/src/v2/components/GameDetails/PrevNextNav.test.ts b/frontend/src/v2/components/GameDetails/PrevNextNav.test.ts index 4e7fea01b..6d9e8716d 100644 --- a/frontend/src/v2/components/GameDetails/PrevNextNav.test.ts +++ b/frontend/src/v2/components/GameDetails/PrevNextNav.test.ts @@ -8,9 +8,7 @@ const { gallery, fromGallery } = vi.hoisted(() => ({ fromGallery: { value: true }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", async (importOriginal) => ({ ...(await importOriginal()), diff --git a/frontend/src/v2/components/GameDetails/SaveDataTab.test.ts b/frontend/src/v2/components/GameDetails/SaveDataTab.test.ts index ca4bceb48..0b53fc70e 100644 --- a/frontend/src/v2/components/GameDetails/SaveDataTab.test.ts +++ b/frontend/src/v2/components/GameDetails/SaveDataTab.test.ts @@ -5,9 +5,7 @@ import storeAuth from "@/stores/auth"; import type { User } from "@/stores/users"; import SaveDataTab from "./SaveDataTab.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", async (importOriginal) => ({ ...(await importOriginal()), useRoute: () => ({ query: {}, path: "/rom/1", params: {} }), diff --git a/frontend/src/v2/components/GameDetails/ScreenshotEditDialog.test.ts b/frontend/src/v2/components/GameDetails/ScreenshotEditDialog.test.ts index ad842e3dc..0e48a812c 100644 --- a/frontend/src/v2/components/GameDetails/ScreenshotEditDialog.test.ts +++ b/frontend/src/v2/components/GameDetails/ScreenshotEditDialog.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import ScreenshotEditDialog from "./ScreenshotEditDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const RDialog = { props: { modelValue: { type: Boolean, default: false } }, diff --git a/frontend/src/v2/components/GameDetails/SubtabNav.test.ts b/frontend/src/v2/components/GameDetails/SubtabNav.test.ts index 318e44dbb..a86e72223 100644 --- a/frontend/src/v2/components/GameDetails/SubtabNav.test.ts +++ b/frontend/src/v2/components/GameDetails/SubtabNav.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import SubtabNav, { type SubtabNavItem } from "./SubtabNav.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const RMenu = { props: { searchable: { type: Boolean, default: false } }, diff --git a/frontend/src/v2/components/GameDetails/UploadAssetDialog.test.ts b/frontend/src/v2/components/GameDetails/UploadAssetDialog.test.ts index 9900ee048..1e0fb22a1 100644 --- a/frontend/src/v2/components/GameDetails/UploadAssetDialog.test.ts +++ b/frontend/src/v2/components/GameDetails/UploadAssetDialog.test.ts @@ -5,9 +5,7 @@ import UploadAssetDialog, { type UploadAssetPayload, } from "./UploadAssetDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/locales", () => ({ default: { global: { t: (key: string) => key } }, })); diff --git a/frontend/src/v2/components/Home/Widgets/AnniversaryWidget.test.ts b/frontend/src/v2/components/Home/Widgets/AnniversaryWidget.test.ts index 1a55073fc..343e86b12 100644 --- a/frontend/src/v2/components/Home/Widgets/AnniversaryWidget.test.ts +++ b/frontend/src/v2/components/Home/Widgets/AnniversaryWidget.test.ts @@ -101,7 +101,6 @@ function loadingOf(wrapper: ReturnType) { describe("AnniversaryWidget", () => { beforeEach(() => { - vi.clearAllMocks(); // 8 September 2026, local time, so the request is asserted against a // known calendar day rather than whenever the suite happens to run. vi.useFakeTimers(); diff --git a/frontend/src/v2/components/Home/Widgets/RandomPickWidget.test.ts b/frontend/src/v2/components/Home/Widgets/RandomPickWidget.test.ts index 31ad7e6f4..0f6ea93b8 100644 --- a/frontend/src/v2/components/Home/Widgets/RandomPickWidget.test.ts +++ b/frontend/src/v2/components/Home/Widgets/RandomPickWidget.test.ts @@ -1,6 +1,6 @@ /* eslint-disable vue/one-component-per-file */ import { flushPromises, mount } from "@vue/test-utils"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { defineComponent } from "vue"; import type { SimpleRom } from "@/stores/roms"; import RandomPickWidget from "./RandomPickWidget.vue"; @@ -10,9 +10,7 @@ const { getRandomRom, snackbarError } = vi.hoisted(() => ({ snackbarError: vi.fn(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/plugins/router", () => ({ ROUTES: { ROM: "rom" }, @@ -70,10 +68,6 @@ function mountWidget() { } describe("RandomPickWidget", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("resolves a pick with a single request", async () => { // Issue #4066: the pick used to cost a count request plus a fetch at a // random offset, which got slower the bigger the library was. diff --git a/frontend/src/v2/components/MatchRom/MatchRomRenameToggle.test.ts b/frontend/src/v2/components/MatchRom/MatchRomRenameToggle.test.ts index 730157a43..af16cf1a8 100644 --- a/frontend/src/v2/components/MatchRom/MatchRomRenameToggle.test.ts +++ b/frontend/src/v2/components/MatchRom/MatchRomRenameToggle.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import { makeRom } from "@/utils/rom.fixtures"; import MatchRomRenameToggle from "./MatchRomRenameToggle.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const rom = makeRom({ fs_name: "Zelda (USA).gba", diff --git a/frontend/src/v2/components/Notifications/NotificationChannelsSection.test.ts b/frontend/src/v2/components/Notifications/NotificationChannelsSection.test.ts index e7cea71fc..9e66e5182 100644 --- a/frontend/src/v2/components/Notifications/NotificationChannelsSection.test.ts +++ b/frontend/src/v2/components/Notifications/NotificationChannelsSection.test.ts @@ -21,9 +21,7 @@ const snackbar = vi.hoisted(() => ({ const confirmDialog = vi.hoisted(() => vi.fn()); vi.mock("@/services/api/notificationChannel", () => ({ default: api })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useSnackbar", async (importOriginal) => ({ ...(await importOriginal()), useSnackbar: () => snackbar, diff --git a/frontend/src/v2/components/Notifications/NotificationInbox.test.ts b/frontend/src/v2/components/Notifications/NotificationInbox.test.ts index a050c10de..439d5144d 100644 --- a/frontend/src/v2/components/Notifications/NotificationInbox.test.ts +++ b/frontend/src/v2/components/Notifications/NotificationInbox.test.ts @@ -19,9 +19,7 @@ const { api, confirm } = vi.hoisted(() => ({ vi.mock("@/services/api/notification", () => ({ default: api })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/utils/notifications", () => ({ describeNotification: (n: NotificationSchema) => ({ diff --git a/frontend/src/v2/components/Notifications/SendNotificationSection.test.ts b/frontend/src/v2/components/Notifications/SendNotificationSection.test.ts index 5b5440d4e..ac2010268 100644 --- a/frontend/src/v2/components/Notifications/SendNotificationSection.test.ts +++ b/frontend/src/v2/components/Notifications/SendNotificationSection.test.ts @@ -11,9 +11,7 @@ const { create, fetchUsers, success } = vi.hoisted(() => ({ vi.mock("@/services/api/notification", () => ({ default: { create } })); vi.mock("@/services/api/user", () => ({ default: { fetchUsers } })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useSnackbar", async (importOriginal) => ({ ...(await importOriginal()), diff --git a/frontend/src/v2/components/Player/AssetPreview.test.ts b/frontend/src/v2/components/Player/AssetPreview.test.ts index fce753e35..bedcbffad 100644 --- a/frontend/src/v2/components/Player/AssetPreview.test.ts +++ b/frontend/src/v2/components/Player/AssetPreview.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import { stateFixture } from "@/utils/assets.fixtures"; import AssetPreview from "./AssetPreview.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/stores/streaming", () => import("@/test-utils/streamingStore")); const RTag = { diff --git a/frontend/src/v2/components/Player/LoadSaveStateDialog.test.ts b/frontend/src/v2/components/Player/LoadSaveStateDialog.test.ts index 0a40c030b..308fb7386 100644 --- a/frontend/src/v2/components/Player/LoadSaveStateDialog.test.ts +++ b/frontend/src/v2/components/Player/LoadSaveStateDialog.test.ts @@ -1,6 +1,6 @@ import { flushPromises, mount } from "@vue/test-utils"; import mitt, { type Emitter } from "mitt"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import type { SaveSchema, StateSchema } from "@/__generated__"; import type { DetailedRom } from "@/stores/roms"; import type { Events } from "@/types/emitter"; @@ -11,9 +11,7 @@ const { confirm } = vi.hoisted(() => ({ confirm: vi.fn(async (_opts: { title: string }) => true), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/stores/streaming", () => import("@/test-utils/streamingStore")); vi.mock("@/v2/composables/useConfirm", () => ({ useConfirm: () => confirm, @@ -86,10 +84,6 @@ function openDialog() { } describe("LoadSaveStateDialog", () => { - beforeEach(() => { - confirm.mockClear(); - }); - it("opens on States and loads a state once confirmed", async () => { const { wrapper, open, stateSelected, saveSelected } = openDialog(); await open(); diff --git a/frontend/src/v2/components/Player/MemoryCardDialog.test.ts b/frontend/src/v2/components/Player/MemoryCardDialog.test.ts index 04775f626..c42fb680e 100644 --- a/frontend/src/v2/components/Player/MemoryCardDialog.test.ts +++ b/frontend/src/v2/components/Player/MemoryCardDialog.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import MemoryCardDialog from "./MemoryCardDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/locales", () => ({ default: { global: { t: (key: string) => key } }, })); diff --git a/frontend/src/v2/components/Player/MemoryCardManager.test.ts b/frontend/src/v2/components/Player/MemoryCardManager.test.ts index 317d7ba18..28e07cce5 100644 --- a/frontend/src/v2/components/Player/MemoryCardManager.test.ts +++ b/frontend/src/v2/components/Player/MemoryCardManager.test.ts @@ -4,9 +4,7 @@ import type { MemoryCardSchema } from "@/__generated__"; import memoryCardApi from "@/services/api/memory-card"; import MemoryCardManager from "./MemoryCardManager.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/memory-card", () => ({ default: { getMemoryCards: vi.fn(), @@ -58,7 +56,6 @@ async function openEdit() { describe("MemoryCardManager edit", () => { beforeEach(() => { - vi.clearAllMocks(); vi.mocked(memoryCardApi.getMemoryCards).mockResolvedValue({ data: [card], } as never); diff --git a/frontend/src/v2/components/Player/PlayerShell.test.ts b/frontend/src/v2/components/Player/PlayerShell.test.ts index 2c540ff16..585cda51a 100644 --- a/frontend/src/v2/components/Player/PlayerShell.test.ts +++ b/frontend/src/v2/components/Player/PlayerShell.test.ts @@ -6,9 +6,7 @@ import PlayerShell from "./PlayerShell.vue"; const mocks = vi.hoisted(() => ({ setStageActive: vi.fn() })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/stores/playing", () => ({ default: () => ({ setStageActive: mocks.setStageActive }), diff --git a/frontend/src/v2/components/Player/SessionEndedReason.test.ts b/frontend/src/v2/components/Player/SessionEndedReason.test.ts index ee74aaab1..1c84df6df 100644 --- a/frontend/src/v2/components/Player/SessionEndedReason.test.ts +++ b/frontend/src/v2/components/Player/SessionEndedReason.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import SessionEndedReason from "./SessionEndedReason.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); describe("SessionEndedReason", () => { it("shows the reason under its label", () => { diff --git a/frontend/src/v2/components/Scan/ScanPlatform.test.ts b/frontend/src/v2/components/Scan/ScanPlatform.test.ts index 4d0f846ee..d74562868 100644 --- a/frontend/src/v2/components/Scan/ScanPlatform.test.ts +++ b/frontend/src/v2/components/Scan/ScanPlatform.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import type { ScanningPlatform } from "@/stores/scanning"; import ScanPlatform from "./ScanPlatform.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); function mountPlatform(overrides: Partial = {}) { const platform: ScanningPlatform = { diff --git a/frontend/src/v2/components/Scan/ScanPlatformRow.test.ts b/frontend/src/v2/components/Scan/ScanPlatformRow.test.ts index 79a62333e..e02ca1391 100644 --- a/frontend/src/v2/components/Scan/ScanPlatformRow.test.ts +++ b/frontend/src/v2/components/Scan/ScanPlatformRow.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import { makeRom } from "@/utils/rom.fixtures"; import ScanPlatformRow from "./ScanPlatformRow.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useWebpSupport", () => ({ useWebpSupport: () => ({ toWebp: (src: string) => src }), })); diff --git a/frontend/src/v2/components/Scan/ScanProviderSelect.test.ts b/frontend/src/v2/components/Scan/ScanProviderSelect.test.ts index 0eb6d6f33..0f234a836 100644 --- a/frontend/src/v2/components/Scan/ScanProviderSelect.test.ts +++ b/frontend/src/v2/components/Scan/ScanProviderSelect.test.ts @@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import type { MetadataOption } from "@/stores/heartbeat"; import ScanProviderSelect from "./ScanProviderSelect.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const provider = (value: string, name: string): MetadataOption => ({ value, diff --git a/frontend/src/v2/components/Settings/FolderMappingsSection.test.ts b/frontend/src/v2/components/Settings/FolderMappingsSection.test.ts index f04fea5bd..77fbcc73b 100644 --- a/frontend/src/v2/components/Settings/FolderMappingsSection.test.ts +++ b/frontend/src/v2/components/Settings/FolderMappingsSection.test.ts @@ -34,9 +34,7 @@ vi.mock("@/services/api/config", () => ({ }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useSnackbar", () => ({ useSnackbar: () => ({ success: vi.fn(), error: vi.fn() }), diff --git a/frontend/src/v2/components/Settings/HiddenGamesPicker.test.ts b/frontend/src/v2/components/Settings/HiddenGamesPicker.test.ts index 7a0c13368..74ec1f944 100644 --- a/frontend/src/v2/components/Settings/HiddenGamesPicker.test.ts +++ b/frontend/src/v2/components/Settings/HiddenGamesPicker.test.ts @@ -6,9 +6,7 @@ import HiddenGamesPicker from "./HiddenGamesPicker.vue"; const { getRoms } = vi.hoisted(() => ({ getRoms: vi.fn() })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@v2/lib", () => { const stub = defineComponent({ template: "" }); diff --git a/frontend/src/v2/components/Settings/PlatformsStatsSection.test.ts b/frontend/src/v2/components/Settings/PlatformsStatsSection.test.ts index fb0b624e1..6151c9e24 100644 --- a/frontend/src/v2/components/Settings/PlatformsStatsSection.test.ts +++ b/frontend/src/v2/components/Settings/PlatformsStatsSection.test.ts @@ -1,5 +1,5 @@ import { mount } from "@vue/test-utils"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { createI18n } from "vue-i18n"; import type { MetadataCoverageItem } from "@/__generated__/models/MetadataCoverageItem"; import type { RegionBreakdownItem } from "@/__generated__/models/RegionBreakdownItem"; @@ -170,10 +170,6 @@ function duplicateSlugLibrary(): Platform[] { } describe("PlatformsStatsSection", () => { - beforeEach(() => { - push.mockClear(); - }); - it("links each row to its platform gallery", async () => { const wrapper = mountSection(duplicateSlugLibrary()); diff --git a/frontend/src/v2/components/Settings/ScanPriorityList.test.ts b/frontend/src/v2/components/Settings/ScanPriorityList.test.ts index 72d1a05a4..da976a928 100644 --- a/frontend/src/v2/components/Settings/ScanPriorityList.test.ts +++ b/frontend/src/v2/components/Settings/ScanPriorityList.test.ts @@ -4,9 +4,7 @@ import ScanPriorityList from "./ScanPriorityList.vue"; // vue-i18n's `t` is stubbed to echo the key so the component mounts without // the full i18n plugin. -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const SOURCES = [ { value: "igdb", label: "IGDB" }, diff --git a/frontend/src/v2/components/shared/AssetActions.test.ts b/frontend/src/v2/components/shared/AssetActions.test.ts index b484562f7..8be0ba8a2 100644 --- a/frontend/src/v2/components/shared/AssetActions.test.ts +++ b/frontend/src/v2/components/shared/AssetActions.test.ts @@ -4,9 +4,7 @@ import type { SaveSchema } from "@/__generated__"; import { saveFixture } from "@/utils/assets.fixtures"; import AssetActions from "./AssetActions.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const RBtn = { props: { ariaLabel: { type: String, default: "" } }, diff --git a/frontend/src/v2/components/shared/AssetChips.test.ts b/frontend/src/v2/components/shared/AssetChips.test.ts index 8ef32e142..b74d76b00 100644 --- a/frontend/src/v2/components/shared/AssetChips.test.ts +++ b/frontend/src/v2/components/shared/AssetChips.test.ts @@ -4,9 +4,7 @@ import type { SaveSchema } from "@/__generated__"; import { saveFixture } from "@/utils/assets.fixtures"; import AssetChips from "./AssetChips.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/stores/streaming", () => import("@/test-utils/streamingStore")); const RTag = { diff --git a/frontend/src/v2/components/shared/ConfirmDialog.test.ts b/frontend/src/v2/components/shared/ConfirmDialog.test.ts index 855b7e613..30adbac21 100644 --- a/frontend/src/v2/components/shared/ConfirmDialog.test.ts +++ b/frontend/src/v2/components/shared/ConfirmDialog.test.ts @@ -1,12 +1,10 @@ import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; import mitt, { type Emitter } from "mitt"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import type { Events } from "@/types/emitter"; import ConfirmDialog from "./ConfirmDialog.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const RBtnStub = { props: { disabled: { type: Boolean, default: false } }, @@ -53,10 +51,6 @@ function confirmButton(wrapper: VueWrapper) { } describe("ConfirmDialog typed confirmation", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - it("keeps the action disabled until the phrase is typed", async () => { const wrapper = await promptFor("Philips Videopac+"); expect(confirmButton(wrapper).attributes("disabled")).toBeDefined(); diff --git a/frontend/src/v2/components/shared/LocationChip.test.ts b/frontend/src/v2/components/shared/LocationChip.test.ts index a081f4aa7..5aa572551 100644 --- a/frontend/src/v2/components/shared/LocationChip.test.ts +++ b/frontend/src/v2/components/shared/LocationChip.test.ts @@ -4,9 +4,7 @@ import LocationChip from "./LocationChip.vue"; const { copy } = vi.hoisted(() => ({ copy: vi.fn() })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useClipboard", () => ({ useClipboard: () => ({ isSupported: true, copy }), diff --git a/frontend/src/v2/components/shared/VisibilitySwitch.test.ts b/frontend/src/v2/components/shared/VisibilitySwitch.test.ts index 550251464..633a72265 100644 --- a/frontend/src/v2/components/shared/VisibilitySwitch.test.ts +++ b/frontend/src/v2/components/shared/VisibilitySwitch.test.ts @@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import VisibilitySwitch from "./VisibilitySwitch.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); describe("VisibilitySwitch", () => { it("keeps both labels in place and shows the one it is on", async () => { diff --git a/frontend/src/v2/components/shared/platformSelect.test.ts b/frontend/src/v2/components/shared/platformSelect.test.ts index f0f819df1..8fed2b0a4 100644 --- a/frontend/src/v2/components/shared/platformSelect.test.ts +++ b/frontend/src/v2/components/shared/platformSelect.test.ts @@ -8,9 +8,7 @@ import { promotePlatformsWithGamesFirst, } from "./platformSelect"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); type Row = Pick; diff --git a/frontend/src/v2/composables/useCanPlay/index.test.ts b/frontend/src/v2/composables/useCanPlay/index.test.ts index f1cd6de16..20b16fcf7 100644 --- a/frontend/src/v2/composables/useCanPlay/index.test.ts +++ b/frontend/src/v2/composables/useCanPlay/index.test.ts @@ -65,12 +65,6 @@ beforeEach(() => { support.pico8Rom.mockReturnValue(false); support.ruffle.mockReturnValue(false); support.jsDosBundle.mockReturnValue(true); - support.ejs.mockClear(); - support.jsDos.mockClear(); - support.pico8.mockClear(); - support.pico8Rom.mockClear(); - support.ruffle.mockClear(); - support.jsDosBundle.mockClear(); streamContainer.value = null; nativeSupported.value = false; }); diff --git a/frontend/src/v2/composables/useClipboard/index.test.ts b/frontend/src/v2/composables/useClipboard/index.test.ts index 86ea14aed..80b0a63ea 100644 --- a/frontend/src/v2/composables/useClipboard/index.test.ts +++ b/frontend/src/v2/composables/useClipboard/index.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { useClipboard } from "./index"; const success = vi.fn(); @@ -16,10 +16,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({ })); function setSecureContext(value: boolean) { - Object.defineProperty(window, "isSecureContext", { - configurable: true, - value, - }); + vi.stubGlobal("isSecureContext", value); } function setClipboard(writeText: ((text: string) => Promise) | null) { @@ -29,11 +26,6 @@ function setClipboard(writeText: ((text: string) => Promise) | null) { }); } -beforeEach(() => { - success.mockClear(); - error.mockClear(); -}); - afterEach(() => { setClipboard(null); }); diff --git a/frontend/src/v2/composables/useCoverFilters/index.test.ts b/frontend/src/v2/composables/useCoverFilters/index.test.ts index a76db8a23..173768f60 100644 --- a/frontend/src/v2/composables/useCoverFilters/index.test.ts +++ b/frontend/src/v2/composables/useCoverFilters/index.test.ts @@ -3,9 +3,7 @@ import { nextTick, ref } from "vue"; import type { CoverResource, SearchCoverSchema } from "@/__generated__"; import { useCoverFilters } from "./index"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); function resource(overrides: Partial = {}): CoverResource { return { diff --git a/frontend/src/v2/composables/useGallerySelectAll/index.test.ts b/frontend/src/v2/composables/useGallerySelectAll/index.test.ts index 4b9a5817e..b8eba9a70 100644 --- a/frontend/src/v2/composables/useGallerySelectAll/index.test.ts +++ b/frontend/src/v2/composables/useGallerySelectAll/index.test.ts @@ -1,5 +1,5 @@ import { flushPromises } from "@vue/test-utils"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import type { SimpleRom } from "@/stores/roms"; import { useGallerySelectAll } from "@/v2/composables/useGallerySelectAll"; import storeGalleryRoms from "@/v2/stores/galleryRoms"; @@ -23,9 +23,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({ }), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); function rom(id: number): SimpleRom { return { id, name: `Game ${id}`, platform_id: 1 } as SimpleRom; @@ -60,15 +58,6 @@ function setupGallery({ } describe("useGallerySelectAll", () => { - beforeEach(() => { - vi.clearAllMocks(); - }); - - afterEach(() => { - // Un-stub the console.error spy from the failure-path test. - vi.restoreAllMocks(); - }); - it("selects the whole filtered result, not just the loaded windows", async () => { setupGallery({ ids: [1, 2, 3, 4], loaded: [rom(1), rom(2)] }); const selection = storeGallerySelection(); diff --git a/frontend/src/v2/composables/useGameActions/index.test.ts b/frontend/src/v2/composables/useGameActions/index.test.ts index db21bef9c..ce53e33f6 100644 --- a/frontend/src/v2/composables/useGameActions/index.test.ts +++ b/frontend/src/v2/composables/useGameActions/index.test.ts @@ -32,9 +32,7 @@ vi.mock("vue", async (importOriginal) => ({ ...(await importOriginal()), inject: () => ({ emit: emitterEmit }), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", () => ({ useRouter: () => ({ push }), })); @@ -163,11 +161,6 @@ function makeRom(status: SimpleRom["rom_user"]["status"] = null): SimpleRom { } beforeEach(() => { - push.mockClear(); - confirmFn.mockClear(); - startScan.mockClear(); - snackbarInfo.mockClear(); - snackbarError.mockClear(); probeFormatDownload.mockReset(); downloadRom.mockReset(); clipboardCopy.mockReset(); diff --git a/frontend/src/v2/composables/useGamepad/index.test.ts b/frontend/src/v2/composables/useGamepad/index.test.ts index 8dfeeabc8..6054abf66 100644 --- a/frontend/src/v2/composables/useGamepad/index.test.ts +++ b/frontend/src/v2/composables/useGamepad/index.test.ts @@ -101,8 +101,6 @@ describe("useGamepad", () => { window.removeEventListener("keydown", onKeydown); wrapper?.unmount(); wrapper = null; - vi.unstubAllGlobals(); - vi.restoreAllMocks(); }); it("steers with the left stick", () => { diff --git a/frontend/src/v2/composables/useGlobalHotkeys/index.test.ts b/frontend/src/v2/composables/useGlobalHotkeys/index.test.ts index fe1091119..49890778a 100644 --- a/frontend/src/v2/composables/useGlobalHotkeys/index.test.ts +++ b/frontend/src/v2/composables/useGlobalHotkeys/index.test.ts @@ -42,7 +42,6 @@ function press(key: string, target: EventTarget = document.body) { } beforeEach(() => { - push.mockClear(); playingStore.playing = false; document.body.innerHTML = ""; }); diff --git a/frontend/src/v2/composables/useIsolatedLaunch/index.test.ts b/frontend/src/v2/composables/useIsolatedLaunch/index.test.ts index ac10aacc4..2dc17b78c 100644 --- a/frontend/src/v2/composables/useIsolatedLaunch/index.test.ts +++ b/frontend/src/v2/composables/useIsolatedLaunch/index.test.ts @@ -1,12 +1,4 @@ -import { - afterAll, - beforeAll, - beforeEach, - describe, - expect, - it, - vi, -} from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { useIsolatedLaunch } from "./index"; interface Intent { @@ -24,17 +16,16 @@ function isIntent(value: unknown): value is Intent { const KEY = "player:7:ejs:launch"; const reload = vi.fn(); -let originalLocation: Location; -const realStorage = window.sessionStorage; /** Stand in for a browser that denies storage access outright. */ function blockStorage() { const denied = () => { throw new Error("storage is blocked"); }; - Object.defineProperty(window, "sessionStorage", { - configurable: true, - value: { getItem: denied, setItem: denied, removeItem: denied }, + vi.stubGlobal("sessionStorage", { + getItem: denied, + setItem: denied, + removeItem: denied, }); } @@ -43,33 +34,11 @@ function launch() { } function setSecureContext(secure: boolean) { - Object.defineProperty(window, "isSecureContext", { - configurable: true, - value: secure, - }); + vi.stubGlobal("isSecureContext", secure); } -beforeAll(() => { - originalLocation = window.location; - Object.defineProperty(window, "location", { - configurable: true, - value: { ...originalLocation, reload }, - }); -}); - -afterAll(() => { - Object.defineProperty(window, "location", { - configurable: true, - value: originalLocation, - }); -}); - beforeEach(() => { - reload.mockClear(); - Object.defineProperty(window, "sessionStorage", { - configurable: true, - value: realStorage, - }); + vi.stubGlobal("location", { ...window.location, reload }); sessionStorage.clear(); setSecureContext(true); }); diff --git a/frontend/src/v2/composables/useJoinStreamConfirm/index.test.ts b/frontend/src/v2/composables/useJoinStreamConfirm/index.test.ts index 501e34353..6f00669f4 100644 --- a/frontend/src/v2/composables/useJoinStreamConfirm/index.test.ts +++ b/frontend/src/v2/composables/useJoinStreamConfirm/index.test.ts @@ -1,12 +1,10 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { useJoinStreamConfirm } from "./index"; const push = vi.fn(); const confirmFn = vi.fn(); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", () => ({ useRouter: () => ({ push }), })); @@ -22,11 +20,6 @@ const target = { }; describe("useJoinStreamConfirm", () => { - beforeEach(() => { - push.mockClear(); - confirmFn.mockClear(); - }); - it("does not navigate until the user confirms", async () => { confirmFn.mockResolvedValue(false); const { joinStream } = useJoinStreamConfirm(); diff --git a/frontend/src/v2/composables/useMediaSession/index.test.ts b/frontend/src/v2/composables/useMediaSession/index.test.ts index 2ad4515fc..2be5814a3 100644 --- a/frontend/src/v2/composables/useMediaSession/index.test.ts +++ b/frontend/src/v2/composables/useMediaSession/index.test.ts @@ -95,7 +95,6 @@ describe("useMediaSession", () => { afterEach(() => { scope.stop(); Reflect.deleteProperty(navigator, "mediaSession"); - vi.unstubAllGlobals(); }); function start(blocked?: () => boolean) { diff --git a/frontend/src/v2/composables/useNativeLaunch/index.test.ts b/frontend/src/v2/composables/useNativeLaunch/index.test.ts index d4b457b2c..8b3e19277 100644 --- a/frontend/src/v2/composables/useNativeLaunch/index.test.ts +++ b/frontend/src/v2/composables/useNativeLaunch/index.test.ts @@ -54,22 +54,13 @@ function feedback() { describe("installNativeLaunchFeedback", () => { beforeEach(() => { emit = null; - install.mockClear(); - nameFor.mockClear(); nameFor.mockImplementation(() => "Chrono Trigger"); - consumeCancelled.mockClear(); - success.mockClear(); - error.mockClear(); - warning.mockClear(); - info.mockClear(); - t.mockClear(); vi.spyOn(console, "error").mockImplementation(() => {}); }); afterEach(() => { wrapper?.unmount(); wrapper = null; - vi.restoreAllMocks(); }); it("subscribes on install", () => { diff --git a/frontend/src/v2/composables/usePendingAssetSync/index.test.ts b/frontend/src/v2/composables/usePendingAssetSync/index.test.ts index 03ad6f621..0fd466605 100644 --- a/frontend/src/v2/composables/usePendingAssetSync/index.test.ts +++ b/frontend/src/v2/composables/usePendingAssetSync/index.test.ts @@ -53,9 +53,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({ }), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const refetchRom = vi.fn(async () => null); vi.mock("@/v2/composables/useRomSync", () => ({ @@ -95,16 +93,11 @@ describe("installPendingAssetSync", () => { isOffline.value = false; syncPendingAssets.mockReset(); syncPendingAssets.mockImplementation(acceptAll); - refetchRom.mockClear(); - success.mockClear(); - error.mockClear(); - warning.mockClear(); }); afterEach(() => { wrapper?.unmount(); wrapper = null; - vi.unstubAllGlobals(); vi.useRealTimers(); }); diff --git a/frontend/src/v2/composables/usePinnedMedia/index.test.ts b/frontend/src/v2/composables/usePinnedMedia/index.test.ts index 45bd27cb3..ff0005b91 100644 --- a/frontend/src/v2/composables/usePinnedMedia/index.test.ts +++ b/frontend/src/v2/composables/usePinnedMedia/index.test.ts @@ -1,3 +1,4 @@ +import { flushPromises } from "@vue/test-utils"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { reactive, shallowRef } from "vue"; import type { RomUserSchema } from "@/__generated__"; @@ -5,9 +6,7 @@ import romApi from "@/services/api/rom"; import type { DetailedRom } from "@/stores/roms"; import { usePinnedMedia } from "./index"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/rom", () => ({ default: { updateUserRomProps: vi.fn() }, @@ -45,10 +44,6 @@ function makeRom(pinnedMedia: string[] | null): DetailedRom { }) as DetailedRom; } -async function settle() { - await new Promise((resolve) => setTimeout(resolve)); -} - beforeEach(() => { update.mockReset(); snackbarError.mockReset(); @@ -66,7 +61,7 @@ describe("usePinnedMedia", () => { togglePin("file:2"); expect(rom.rom_user.pinned_media).toEqual(["file:1", "file:2"]); expect(isCustomized.value).toBe(true); - await settle(); + await flushPromises(); expect(update).toHaveBeenCalledWith({ romId: rom.id, data: { pinned_media: ["file:1", "file:2"] }, @@ -84,17 +79,17 @@ describe("usePinnedMedia", () => { screenshots.togglePin("file:1"); artwork.togglePin("file:2"); - await settle(); + await flushPromises(); expect(update).toHaveBeenCalledTimes(1); releases[0](); - await settle(); + await flushPromises(); expect(update).toHaveBeenCalledTimes(2); expect(update.mock.calls[1][0].data).toEqual({ pinned_media: ["file:1", "file:2"], }); releases[1](); - await settle(); + await flushPromises(); }); it("restores the previous pins and reports a failed write", async () => { @@ -104,7 +99,7 @@ describe("usePinnedMedia", () => { togglePin("file:1"); expect(rom.rom_user.pinned_media).toEqual([]); - await settle(); + await flushPromises(); expect(rom.rom_user.pinned_media).toEqual(["file:1"]); expect(snackbarError).toHaveBeenCalledWith( "rom.pinned-media-update-failed", @@ -121,7 +116,7 @@ describe("usePinnedMedia", () => { togglePin("file:1"); togglePin("file:2"); - await settle(); + await flushPromises(); expect(rom.rom_user.pinned_media).toEqual(["file:1", "file:2"]); expect(snackbarError).toHaveBeenCalledOnce(); }); @@ -133,7 +128,7 @@ describe("usePinnedMedia", () => { togglePin("file:1"); togglePin("file:2"); - await settle(); + await flushPromises(); expect(rom.rom_user.pinned_media).toEqual(["file:9"]); }); @@ -149,7 +144,7 @@ describe("usePinnedMedia", () => { rom_user: { pinned_media: [] as string[] } as RomUserSchema, }) as DetailedRom; current.value = refetched; - await settle(); + await flushPromises(); expect(refetched.rom_user.pinned_media).toEqual(["file:1"]); }); @@ -158,7 +153,7 @@ describe("usePinnedMedia", () => { const { togglePin } = usePinnedMedia(rom); togglePin("file:4"); - await settle(); + await flushPromises(); expect(rom.rom_user.pinned_media).toEqual(["file:1", "file:2", "file:3"]); expect(update).not.toHaveBeenCalled(); expect(snackbarError).toHaveBeenCalledWith( @@ -182,7 +177,7 @@ describe("usePinnedMedia", () => { resetPins(); expect(rom.rom_user.pinned_media).toBeNull(); - await settle(); + await flushPromises(); expect(update).toHaveBeenCalledWith({ romId: rom.id, data: { pinned_media: null }, diff --git a/frontend/src/v2/composables/usePlayerExit/index.test.ts b/frontend/src/v2/composables/usePlayerExit/index.test.ts index e9b3d5c91..9c34d1163 100644 --- a/frontend/src/v2/composables/usePlayerExit/index.test.ts +++ b/frontend/src/v2/composables/usePlayerExit/index.test.ts @@ -1,50 +1,22 @@ import { flushPromises } from "@vue/test-utils"; -import { - afterAll, - afterEach, - beforeAll, - describe, - expect, - it, - vi, -} from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { installFullscreenFallback } from "@/v2/utils/playerFullscreen"; import { usePlayerExit } from "./index"; const replace = vi.fn(); const locationReplace = vi.fn(); -let originalLocation: Location; vi.mock("vue-router", () => ({ useRouter: () => ({ replace }), })); function setIsolated(isolated: boolean) { - Object.defineProperty(window, "crossOriginIsolated", { - configurable: true, - value: isolated, - }); + vi.stubGlobal("crossOriginIsolated", isolated); } -beforeAll(() => { - originalLocation = window.location; - Object.defineProperty(window, "location", { - configurable: true, - value: { ...originalLocation, replace: locationReplace }, - }); -}); - -afterAll(() => { - Object.defineProperty(window, "location", { - configurable: true, - value: originalLocation, - }); -}); - -afterEach(() => { - replace.mockClear(); +beforeEach(() => { + vi.stubGlobal("location", { ...window.location, replace: locationReplace }); locationReplace.mockReset(); - setIsolated(false); }); describe("usePlayerExit", () => { @@ -150,9 +122,7 @@ describe("usePlayerExit", () => { it("replaces the document even when settling fails", async () => { setIsolated(true); - const error = vi - .spyOn(console, "error") - .mockImplementation(() => undefined); + vi.spyOn(console, "error").mockImplementation(() => undefined); const exit = usePlayerExit( () => false, () => Promise.reject(new Error("nope")), @@ -162,7 +132,6 @@ describe("usePlayerExit", () => { await flushPromises(); expect(locationReplace).toHaveBeenCalledWith("/platform/2"); - error.mockRestore(); }); // The view arms an unload prompt while a game is up, and the exit it asked diff --git a/frontend/src/v2/composables/usePlayerFullscreen/index.test.ts b/frontend/src/v2/composables/usePlayerFullscreen/index.test.ts index b84506f16..022421e9a 100644 --- a/frontend/src/v2/composables/usePlayerFullscreen/index.test.ts +++ b/frontend/src/v2/composables/usePlayerFullscreen/index.test.ts @@ -49,7 +49,6 @@ describe("usePlayerFullscreen", () => { await expect(value.exit()).resolves.toBeUndefined(); expect(error).toHaveBeenCalledOnce(); - error.mockRestore(); }); it("swallows a denied request instead of rejecting", async () => { diff --git a/frontend/src/v2/composables/useReducedMotion/index.test.ts b/frontend/src/v2/composables/useReducedMotion/index.test.ts index a5c396a9f..9c6522f11 100644 --- a/frontend/src/v2/composables/useReducedMotion/index.test.ts +++ b/frontend/src/v2/composables/useReducedMotion/index.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { nextTick } from "vue"; const KEY = "settings.v2.reducedMotion"; @@ -23,16 +23,19 @@ let store: Storage; // Force the OS `prefers-reduced-motion` result the next fresh import will read. function stubReducedMotion(matches: boolean) { - window.matchMedia = vi.fn().mockImplementation((query: string) => ({ - matches, - media: query, - onchange: null, - addEventListener: vi.fn(), - removeEventListener: vi.fn(), - addListener: vi.fn(), - removeListener: vi.fn(), - dispatchEvent: vi.fn(), - })); + vi.stubGlobal( + "matchMedia", + vi.fn().mockImplementation((query: string) => ({ + matches, + media: query, + onchange: null, + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + addListener: vi.fn(), + removeListener: vi.fn(), + dispatchEvent: vi.fn(), + })), + ); } // `override` / `systemPreference` / `enabled` are module-level singletons @@ -45,24 +48,12 @@ async function loadFresh() { return useReducedMotion(); } -const realMatchMedia = window.matchMedia; - beforeEach(() => { store = makeStorage(); vi.stubGlobal("localStorage", store); - Object.defineProperty(window, "localStorage", { - value: store, - configurable: true, - writable: true, - }); stubReducedMotion(false); }); -afterEach(() => { - vi.unstubAllGlobals(); - window.matchMedia = realMatchMedia; -}); - describe("useReducedMotion", () => { it("defaults to the system prefers-reduced-motion setting when unset", async () => { stubReducedMotion(true); diff --git a/frontend/src/v2/composables/useResponsiveColumns/index.test.ts b/frontend/src/v2/composables/useResponsiveColumns/index.test.ts index 9e759e89b..e1b3c64ef 100644 --- a/frontend/src/v2/composables/useResponsiveColumns/index.test.ts +++ b/frontend/src/v2/composables/useResponsiveColumns/index.test.ts @@ -1,5 +1,5 @@ import { mount } from "@vue/test-utils"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it } from "vitest"; import { defineComponent, h, nextTick, ref } from "vue"; import { stubResizeObserver } from "@/test-utils/resizeObserver"; import { useResponsiveColumns } from "./index"; @@ -29,7 +29,6 @@ describe("useResponsiveColumns", () => { observer = stubResizeObserver(); cardWidth.value = 158; }); - afterEach(() => vi.unstubAllGlobals()); it("derives the column count from the observed width", async () => { const wrapper = await mountHost(); diff --git a/frontend/src/v2/composables/useRomFileUpload/index.test.ts b/frontend/src/v2/composables/useRomFileUpload/index.test.ts index 83a384f37..33997c04d 100644 --- a/frontend/src/v2/composables/useRomFileUpload/index.test.ts +++ b/frontend/src/v2/composables/useRomFileUpload/index.test.ts @@ -14,9 +14,7 @@ const { uploadRoms, refetchRom, confirmFn, snackbar } = vi.hoisted(() => ({ }, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api/rom", () => ({ default: { uploadRoms }, })); @@ -37,7 +35,6 @@ const exists = { isAxiosError: true, response: { status: 409 } }; describe("useRomFileUpload", () => { beforeEach(() => { - vi.clearAllMocks(); uploadRoms.mockResolvedValue([{ status: "fulfilled", value: null }]); confirmFn.mockResolvedValue(true); }); diff --git a/frontend/src/v2/composables/useRomScanRefresh/index.test.ts b/frontend/src/v2/composables/useRomScanRefresh/index.test.ts index 2735b38ea..16d8bc178 100644 --- a/frontend/src/v2/composables/useRomScanRefresh/index.test.ts +++ b/frontend/src/v2/composables/useRomScanRefresh/index.test.ts @@ -48,7 +48,6 @@ async function install(path: string) { describe("useRomScanRefresh", () => { beforeEach(() => { handlers.clear(); - refetchRom.mockClear(); }); it("refetches the open rom when a scan finishes", async () => { diff --git a/frontend/src/v2/composables/useScanLifecycle/index.test.ts b/frontend/src/v2/composables/useScanLifecycle/index.test.ts index ecce90778..4b71e3d69 100644 --- a/frontend/src/v2/composables/useScanLifecycle/index.test.ts +++ b/frontend/src/v2/composables/useScanLifecycle/index.test.ts @@ -1,4 +1,4 @@ -import { mount } from "@vue/test-utils"; +import { flushPromises, mount } from "@vue/test-utils"; import mitt from "mitt"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { defineComponent, reactive } from "vue"; @@ -54,9 +54,6 @@ vi.mock("@/stores/auth", () => ({ const getTaskStatus = vi.mocked(taskApi.getTaskStatus); -/** Drain pending microtasks so the reconcile's promise chain has settled. */ -const flushPromises = () => new Promise((resolve) => setTimeout(resolve, 0)); - /** Outlast the handler's 100ms batching debounce for `scan:scanning_rom`. */ const drainRomBatch = () => new Promise((resolve) => setTimeout(resolve, 150)); diff --git a/frontend/src/v2/composables/useScanProviders/index.test.ts b/frontend/src/v2/composables/useScanProviders/index.test.ts index aee791a7f..29e5cf9be 100644 --- a/frontend/src/v2/composables/useScanProviders/index.test.ts +++ b/frontend/src/v2/composables/useScanProviders/index.test.ts @@ -24,9 +24,7 @@ const heartbeat = { }; const config = ref({ SKIP_HASH_CALCULATION: false }); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("pinia", () => ({ storeToRefs: () => ({ config }), })); diff --git a/frontend/src/v2/composables/useScanTrigger/index.test.ts b/frontend/src/v2/composables/useScanTrigger/index.test.ts index faa9147df..ee3721fe3 100644 --- a/frontend/src/v2/composables/useScanTrigger/index.test.ts +++ b/frontend/src/v2/composables/useScanTrigger/index.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import storeScanning from "@/stores/scanning"; import { useScanTrigger } from "./index"; @@ -8,9 +8,7 @@ const { emit, connect, warning } = vi.hoisted(() => ({ warning: vi.fn(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/socket", () => ({ default: { connected: false, connect, emit }, })); @@ -19,12 +17,6 @@ vi.mock("@/v2/composables/useSnackbar", () => ({ })); describe("useScanTrigger", () => { - beforeEach(() => { - emit.mockClear(); - connect.mockClear(); - warning.mockClear(); - }); - it("flips the store, connects and emits one event per payload", () => { const { startScan } = useScanTrigger(); diff --git a/frontend/src/v2/composables/useServerConnection/index.test.ts b/frontend/src/v2/composables/useServerConnection/index.test.ts index b9c73e21f..ed1acf321 100644 --- a/frontend/src/v2/composables/useServerConnection/index.test.ts +++ b/frontend/src/v2/composables/useServerConnection/index.test.ts @@ -1,13 +1,4 @@ -import { - afterAll, - afterEach, - beforeAll, - beforeEach, - describe, - expect, - it, - vi, -} from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { nextTick, reactive } from "vue"; import { shouldRefreshOnReconnect } from "./index"; @@ -30,7 +21,6 @@ vi.mock("@/stores/heartbeat", () => ({ default: () => heartbeatStore })); vi.mock("@/stores/playing", () => ({ default: () => playingStore })); const reload = vi.fn(); -let originalLocation: Location; // `installed` is module state, so each test needs a fresh module to install // its own watchers. @@ -61,24 +51,9 @@ function quiesce() { document.dispatchEvent(new CustomEvent("network-quiesced")); } -beforeAll(() => { - originalLocation = window.location; - Object.defineProperty(window, "location", { - configurable: true, - value: { ...originalLocation, reload }, - }); -}); - -afterAll(() => { - Object.defineProperty(window, "location", { - configurable: true, - value: originalLocation, - }); -}); - beforeEach(() => { + vi.stubGlobal("location", { ...window.location, reload }); vi.useFakeTimers(); - reload.mockClear(); heartbeatStore = makeHeartbeatStore(); playingStore = reactive({ playing: false }); }); diff --git a/frontend/src/v2/composables/useSpatialNav/index.test.ts b/frontend/src/v2/composables/useSpatialNav/index.test.ts index c697154e6..fa8e8e8be 100644 --- a/frontend/src/v2/composables/useSpatialNav/index.test.ts +++ b/frontend/src/v2/composables/useSpatialNav/index.test.ts @@ -112,7 +112,6 @@ describe("useSpatialNav", () => { } beforeEach(() => { - scrollIntoView.mockClear(); stub("getBoundingClientRect", { value(this: HTMLElement) { if (this.dataset.x === undefined) return new DOMRect(0, 0, 0, 0); @@ -203,7 +202,6 @@ describe("useSpatialNav", () => { expect(scrollIntoView).toHaveBeenCalledWith( expect.objectContaining({ block: "center" }), ); - vi.unstubAllGlobals(); }); it("skips controls a roving tabindex has taken out of the tab order", () => { diff --git a/frontend/src/v2/composables/useTrackPager/index.test.ts b/frontend/src/v2/composables/useTrackPager/index.test.ts index 7b1eeb490..363ea9761 100644 --- a/frontend/src/v2/composables/useTrackPager/index.test.ts +++ b/frontend/src/v2/composables/useTrackPager/index.test.ts @@ -1,3 +1,4 @@ +import { flushPromises } from "@vue/test-utils"; import { describe, expect, it, vi } from "vitest"; import type { MusicTrackSchema } from "@/__generated__"; import { TRACK_PAGE_SIZE, useTrackPager } from "./index"; @@ -56,7 +57,7 @@ describe("useTrackPager", () => { expect(calls).toEqual([0]); pager.loadMoreIfNear(TRACK_PAGE_SIZE - 1); - await new Promise((r) => setTimeout(r, 0)); + await flushPromises(); expect(calls).toEqual([0, TRACK_PAGE_SIZE]); }); diff --git a/frontend/src/v2/composables/useViewTransition/index.test.ts b/frontend/src/v2/composables/useViewTransition/index.test.ts index e6b78e915..38d78dd1f 100644 --- a/frontend/src/v2/composables/useViewTransition/index.test.ts +++ b/frontend/src/v2/composables/useViewTransition/index.test.ts @@ -1,3 +1,4 @@ +import { flushPromises } from "@vue/test-utils"; import { afterEach, describe, expect, it, vi } from "vitest"; import { createMemoryHistory, createRouter } from "vue-router"; import { expectNoUnhandledRejection } from "@/test-utils/unhandledRejection"; @@ -65,7 +66,7 @@ describe("morphTransition", () => { morphTransition({ el, name: "rom-cover-1" }, () => {}); expect(el.style.viewTransitionName).toBe("rom-cover-1"); await finished; - await new Promise((resolve) => setTimeout(resolve, 0)); + await flushPromises(); expect(el.style.viewTransitionName).toBe(""); el.remove(); diff --git a/frontend/src/v2/composables/useWrapGridNav/index.test.ts b/frontend/src/v2/composables/useWrapGridNav/index.test.ts index 3a8a936cc..8ba1a4342 100644 --- a/frontend/src/v2/composables/useWrapGridNav/index.test.ts +++ b/frontend/src/v2/composables/useWrapGridNav/index.test.ts @@ -72,7 +72,6 @@ describe("useWrapGridNav", () => { beforeEach(() => { setModality("mouse"); - scrollIntoView.mockClear(); stub("offsetParent", { get(this: HTMLElement) { return this.parentElement; diff --git a/frontend/src/v2/layouts/AuthLayout.test.ts b/frontend/src/v2/layouts/AuthLayout.test.ts index 0870d0a93..9b14e855a 100644 --- a/frontend/src/v2/layouts/AuthLayout.test.ts +++ b/frontend/src/v2/layouts/AuthLayout.test.ts @@ -5,9 +5,7 @@ import { nextTick } from "vue"; import type { Events } from "@/types/emitter"; import AuthLayout from "./AuthLayout.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/v2/composables/useBreakpoint", () => ({ installBreakpointAttribute: vi.fn(), diff --git a/frontend/src/v2/lib/forms/RComboboxField/RComboboxField.test.ts b/frontend/src/v2/lib/forms/RComboboxField/RComboboxField.test.ts index 175249218..8bff0e799 100644 --- a/frontend/src/v2/lib/forms/RComboboxField/RComboboxField.test.ts +++ b/frontend/src/v2/lib/forms/RComboboxField/RComboboxField.test.ts @@ -46,7 +46,6 @@ describe("RComboboxField inside an overlay", () => { afterEach(() => { popEscapable(dialog); - vi.mocked(dialog.close).mockClear(); }); function pressEscape(el: Element) { diff --git a/frontend/src/v2/lib/forms/RSelect/RSelect.test.ts b/frontend/src/v2/lib/forms/RSelect/RSelect.test.ts index 24760ea4d..87c9d87f0 100644 --- a/frontend/src/v2/lib/forms/RSelect/RSelect.test.ts +++ b/frontend/src/v2/lib/forms/RSelect/RSelect.test.ts @@ -207,7 +207,6 @@ describe("RSelect inside an overlay", () => { afterEach(() => { popEscapable(dialog); - vi.mocked(dialog.close).mockClear(); }); it("closes only its own menu on Escape, leaving the dialog open", async () => { diff --git a/frontend/src/v2/lib/forms/RTextField/RTextField.test.ts b/frontend/src/v2/lib/forms/RTextField/RTextField.test.ts index 868cccc3e..3399e78ce 100644 --- a/frontend/src/v2/lib/forms/RTextField/RTextField.test.ts +++ b/frontend/src/v2/lib/forms/RTextField/RTextField.test.ts @@ -1,5 +1,5 @@ import { mount } from "@vue/test-utils"; -import { afterEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { nextTick } from "vue"; import RTextField from "./RTextField.vue"; @@ -9,10 +9,6 @@ const POPUP = { kind: "dialog", } as const; -afterEach(() => { - vi.restoreAllMocks(); -}); - describe("RTextField popup wiring", () => { it("puts the combobox role on the input, not the outer element", () => { const wrapper = mount(RTextField, { diff --git a/frontend/src/v2/stores/galleryRoms.test.ts b/frontend/src/v2/stores/galleryRoms.test.ts index 453bc4836..e19300498 100644 --- a/frontend/src/v2/stores/galleryRoms.test.ts +++ b/frontend/src/v2/stores/galleryRoms.test.ts @@ -1,6 +1,6 @@ import { flushPromises } from "@vue/test-utils"; import { createPinia, setActivePinia } from "pinia"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import storeGalleryFilter from "@/stores/galleryFilter"; import storePlatforms, { type Platform } from "@/stores/platforms"; // Import after the mock so the store binds to the mocked rom API. @@ -67,10 +67,6 @@ describe("galleryRoms windowed fetch", () => { }); }); - afterEach(() => { - vi.unstubAllGlobals(); - }); - // The backend ranks a search by relevance only when no sort key is sent. it("sends an empty sort key when no sort is set", () => { getRoms.mockImplementation(() => Promise.resolve(windowResponse())); @@ -462,10 +458,6 @@ describe("galleryRoms length filter", () => { }); }); - afterEach(() => { - vi.unstubAllGlobals(); - }); - it("sends the hour bounds to the API as seconds", () => { storeGalleryFilter().setSelectedFilterLengthHours(5, 20); @@ -494,10 +486,6 @@ describe("galleryRoms relevance order", () => { }); }); - afterEach(() => { - vi.unstubAllGlobals(); - }); - async function answeredWith(charIndex: Record, total = 5) { getRoms.mockResolvedValue({ data: { total, items: [], char_index: charIndex, rom_id_index: [] }, diff --git a/frontend/src/v2/utils/metadataProviderGroups.test.ts b/frontend/src/v2/utils/metadataProviderGroups.test.ts index d8eccf91c..82930cf57 100644 --- a/frontend/src/v2/utils/metadataProviderGroups.test.ts +++ b/frontend/src/v2/utils/metadataProviderGroups.test.ts @@ -20,9 +20,7 @@ import { SETUP_GROUP_LABELS, } from "./metadataProviderGroups"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@/services/api", () => ({ default: { get: vi.fn().mockResolvedValue({ data: {} }) }, diff --git a/frontend/src/v2/utils/pico8Audio.test.ts b/frontend/src/v2/utils/pico8Audio.test.ts index 4ea62ec4a..e473a558b 100644 --- a/frontend/src/v2/utils/pico8Audio.test.ts +++ b/frontend/src/v2/utils/pico8Audio.test.ts @@ -37,7 +37,6 @@ let contextThrows = false; beforeEach(() => { posted.length = 0; - vi.clearAllMocks(); contextThrows = false; sampleRateAsked = undefined; port.onmessage = null; diff --git a/frontend/src/v2/utils/pico8Input.test.ts b/frontend/src/v2/utils/pico8Input.test.ts index df0f2890e..914d00096 100644 --- a/frontend/src/v2/utils/pico8Input.test.ts +++ b/frontend/src/v2/utils/pico8Input.test.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { createPico8Input } from "./pico8Input"; import { PICO8_INPUT_BITS } from "./pico8Runtime"; @@ -21,10 +21,6 @@ function stubPads(...pads: (Gamepad | null)[]) { vi.stubGlobal("navigator", { getGamepads: () => pads }); } -afterEach(() => { - vi.unstubAllGlobals(); -}); - describe("createPico8Input", () => { describe("keyboard", () => { it("maps the arrow keys and Z/X, and claims only those", () => { diff --git a/frontend/src/v2/utils/pico8Runtime.test.ts b/frontend/src/v2/utils/pico8Runtime.test.ts index e3a48d12d..8e4263b93 100644 --- a/frontend/src/v2/utils/pico8Runtime.test.ts +++ b/frontend/src/v2/utils/pico8Runtime.test.ts @@ -52,7 +52,6 @@ vi.mock("./scriptLoader", () => ({ })); beforeEach(() => { - vi.clearAllMocks(); nextAddress = 200; heap[100] = 0x21; vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue( diff --git a/frontend/src/v2/views/CollectionsIndex.test.ts b/frontend/src/v2/views/CollectionsIndex.test.ts index 92ff81e30..f8dd6ca6d 100644 --- a/frontend/src/v2/views/CollectionsIndex.test.ts +++ b/frontend/src/v2/views/CollectionsIndex.test.ts @@ -9,9 +9,7 @@ import storeCollections, { } from "@/stores/collections"; import CollectionsIndex from "./CollectionsIndex.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); // Plain object rather than a reactive route: every test sets the query // before mounting, which is when the view reads it. diff --git a/frontend/src/v2/views/Gallery/Collection.test.ts b/frontend/src/v2/views/Gallery/Collection.test.ts index 65abf6182..f04a000b7 100644 --- a/frontend/src/v2/views/Gallery/Collection.test.ts +++ b/frontend/src/v2/views/Gallery/Collection.test.ts @@ -35,9 +35,7 @@ const { snackbarInfo: vi.fn(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const { routeState } = vi.hoisted(() => ({ routeState: { @@ -179,7 +177,6 @@ function runRouteGuards(name: string, collection: string) { describe("Collection view random rom", () => { beforeEach(() => { - vi.clearAllMocks(); routeGuards.length = 0; routeState.name = "collection"; routeState.params = { collection: "1" }; @@ -372,12 +369,9 @@ describe("Collection view random rom", () => { }); }); -// The store's lists load once per session, so a cached ROM count disagrees -// with the gallery below it. // Opens collection 1. `collection()` caches 9000 ROMs, so any other count came // from the server. function openCachedCollection() { - vi.clearAllMocks(); routeGuards.length = 0; routeState.name = "collection"; routeState.params = { collection: "1" }; @@ -388,6 +382,8 @@ function openCachedCollection() { storeCollections().setCollections([collection(1)]); } +// The store's lists load once per session, so a cached ROM count disagrees +// with the gallery below it. describe("Collection view freshness", () => { beforeEach(openCachedCollection); diff --git a/frontend/src/v2/views/Gallery/Platform.test.ts b/frontend/src/v2/views/Gallery/Platform.test.ts index 1c1872723..04dc36db4 100644 --- a/frontend/src/v2/views/Gallery/Platform.test.ts +++ b/frontend/src/v2/views/Gallery/Platform.test.ts @@ -38,9 +38,7 @@ const { snackbarInfo: vi.fn(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const { routeState } = vi.hoisted(() => ({ routeState: { @@ -205,7 +203,6 @@ async function mountView() { describe("Platform view random rom", () => { beforeEach(() => { - vi.clearAllMocks(); routeState.name = "platform"; routeState.path = "/platform/1"; routeState.params = { platform: "1" }; diff --git a/frontend/src/v2/views/Jukebox/BrowseMode.test.ts b/frontend/src/v2/views/Jukebox/BrowseMode.test.ts index af61ed13d..51e0fdad7 100644 --- a/frontend/src/v2/views/Jukebox/BrowseMode.test.ts +++ b/frontend/src/v2/views/Jukebox/BrowseMode.test.ts @@ -4,9 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { defineComponent } from "vue"; import BrowseMode from "./BrowseMode.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("@v2/lib", () => { const stub = defineComponent({ template: "
" }); diff --git a/frontend/src/v2/views/Notifications.test.ts b/frontend/src/v2/views/Notifications.test.ts index c834e5d48..c24adf11d 100644 --- a/frontend/src/v2/views/Notifications.test.ts +++ b/frontend/src/v2/views/Notifications.test.ts @@ -17,9 +17,7 @@ vi.mock("vue-router", async (importOriginal) => ({ useRouter: () => ({ replace, currentRoute: { value: route } }), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); const stub = (name: string) => defineComponent({ name, template: `
` }); diff --git a/frontend/src/v2/views/PlatformsIndex.test.ts b/frontend/src/v2/views/PlatformsIndex.test.ts index da97f6709..ad963a054 100644 --- a/frontend/src/v2/views/PlatformsIndex.test.ts +++ b/frontend/src/v2/views/PlatformsIndex.test.ts @@ -5,9 +5,7 @@ import { defineComponent, ref } from "vue"; import storePlatforms, { type Platform } from "@/stores/platforms"; import PlatformsIndex from "./PlatformsIndex.vue"; -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); // Plain object rather than a reactive route: every test sets the query // before mounting, which is when the view reads it. diff --git a/frontend/src/v2/views/Player/Desktop.test.ts b/frontend/src/v2/views/Player/Desktop.test.ts index 893986feb..5ade08460 100644 --- a/frontend/src/v2/views/Player/Desktop.test.ts +++ b/frontend/src/v2/views/Player/Desktop.test.ts @@ -1,5 +1,5 @@ import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { defineComponent } from "vue"; import { serverError } from "@/test-utils/serverError"; import Desktop from "./Desktop.vue"; @@ -118,10 +118,6 @@ function expectReleasedOwnClaim(): void { ); } -beforeEach(() => { - vi.clearAllMocks(); -}); - afterEach(() => { mounted?.unmount(); mounted = null; diff --git a/frontend/src/v2/views/Player/JsDos.test.ts b/frontend/src/v2/views/Player/JsDos.test.ts index 02a9a9016..8aeb38ece 100644 --- a/frontend/src/v2/views/Player/JsDos.test.ts +++ b/frontend/src/v2/views/Player/JsDos.test.ts @@ -1,13 +1,5 @@ import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; -import { - afterAll, - beforeAll, - beforeEach, - describe, - expect, - it, - vi, -} from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { nextTick } from "vue"; import type { JsDosOptions, JsDosProps } from "@/types/js-dos"; import JsDos from "./JsDos.vue"; @@ -29,9 +21,7 @@ const mocks = vi.hoisted(() => ({ userId: 7, })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", () => ({ onBeforeRouteLeave: (guard: (to: { fullPath: string }) => unknown) => { @@ -123,45 +113,20 @@ const rom = { const LOCAL_BASE = "/assets/jsdos"; const CDN_BASE = "https://cdn.example/js-dos/dist"; -let originalLocation: Location; - // The launch needs SharedArrayBuffer for the threaded DOSBox-X build, and a // document that has it is one the reload no longer has to produce. function setIsolated(isolated: boolean) { - Object.defineProperty(window, "crossOriginIsolated", { - configurable: true, - value: isolated, - }); - Object.defineProperty(window, "SharedArrayBuffer", { - configurable: true, - value: isolated ? ArrayBuffer : undefined, - }); + vi.stubGlobal("crossOriginIsolated", isolated); + vi.stubGlobal("SharedArrayBuffer", isolated ? ArrayBuffer : undefined); } -beforeAll(() => { - originalLocation = window.location; - Object.defineProperty(window, "location", { - configurable: true, - value: { - ...originalLocation, - reload: mocks.locationReload, - replace: mocks.locationReplace, - }, +beforeEach(() => { + vi.stubGlobal("location", { + ...window.location, + reload: mocks.locationReload, + replace: mocks.locationReplace, }); vi.spyOn(console, "error").mockImplementation(() => undefined); -}); - -afterAll(() => { - vi.unstubAllGlobals(); - vi.restoreAllMocks(); - Object.defineProperty(window, "location", { - configurable: true, - value: originalLocation, - }); -}); - -beforeEach(() => { - vi.clearAllMocks(); sessionStorage.clear(); setIsolated(true); mocks.loadRuntime.mockResolvedValue(LOCAL_BASE); @@ -250,10 +215,7 @@ describe("JsDos runtime loading", () => { // one. See useIsolatedLaunch. describe("JsDos isolated launch", () => { function setSecureContext(secure: boolean) { - Object.defineProperty(window, "isSecureContext", { - configurable: true, - value: secure, - }); + vi.stubGlobal("isSecureContext", secure); } it("reloads into an isolated document instead of booting without one", async () => { diff --git a/frontend/src/v2/views/Player/Ruffle.test.ts b/frontend/src/v2/views/Player/Ruffle.test.ts index b95969e5c..0d4ce0340 100644 --- a/frontend/src/v2/views/Player/Ruffle.test.ts +++ b/frontend/src/v2/views/Player/Ruffle.test.ts @@ -1,13 +1,5 @@ import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; -import { - afterAll, - beforeAll, - beforeEach, - describe, - expect, - it, - vi, -} from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { nextTick } from "vue"; import type { RuffleSourceAPI } from "@/types/ruffle"; import Ruffle from "./Ruffle.vue"; @@ -21,9 +13,7 @@ const mocks = vi.hoisted(() => ({ setStageActive: vi.fn(), })); -vi.mock("vue-i18n", () => ({ - useI18n: () => ({ t: (key: string) => key }), -})); +vi.mock("vue-i18n"); vi.mock("vue-router", () => ({ useRoute: () => ({ params: { rom: "1" } }), @@ -92,19 +82,14 @@ const rom = { // Swallow the Ruffle runtime