From 5b5018bac5f86a84dad64b895f2db1b4e0d7965f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 10:01:37 +0100 Subject: [PATCH] Tests: load channel command mocks before subjects --- src/commands/channels.add.test.ts | 9 +++++++-- src/commands/channels.remove.test.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/commands/channels.add.test.ts b/src/commands/channels.add.test.ts index ac2355ad10d..18da5b60f59 100644 --- a/src/commands/channels.add.test.ts +++ b/src/commands/channels.add.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { ChannelPluginCatalogEntry } from "../channels/plugins/catalog.js"; import type { ChannelPlugin } from "../channels/plugins/types.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; @@ -8,7 +8,6 @@ import { ensureChannelSetupPluginInstalled, loadChannelSetupPluginRegistrySnapshotForChannel, } from "./channel-setup/plugin-install.js"; -import { channelsAddCommand } from "./channels.js"; import { configMocks, offsetMocks } from "./channels.mock-harness.js"; import { createMSTeamsCatalogEntry, @@ -16,6 +15,8 @@ import { } from "./channels.plugin-install.test-helpers.js"; import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js"; +let channelsAddCommand: typeof import("./channels.js").channelsAddCommand; + const catalogMocks = vi.hoisted(() => ({ listChannelPluginCatalogEntries: vi.fn((): ChannelPluginCatalogEntry[] => []), })); @@ -225,6 +226,10 @@ async function runSignalAddCommand(afterAccountConfigWritten: SignalAfterAccount } describe("channelsAddCommand", () => { + beforeAll(async () => { + ({ channelsAddCommand } = await import("./channels.js")); + }); + beforeEach(async () => { configMocks.readConfigFileSnapshot.mockClear(); configMocks.writeConfigFile.mockClear(); diff --git a/src/commands/channels.remove.test.ts b/src/commands/channels.remove.test.ts index 0cfb6180963..01c59359c52 100644 --- a/src/commands/channels.remove.test.ts +++ b/src/commands/channels.remove.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { ChannelPluginCatalogEntry } from "../channels/plugins/catalog.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; import { createTestRegistry } from "../test-utils/channel-plugins.js"; @@ -6,7 +6,6 @@ import { ensureChannelSetupPluginInstalled, loadChannelSetupPluginRegistrySnapshotForChannel, } from "./channel-setup/plugin-install.js"; -import { channelsRemoveCommand } from "./channels.js"; import { configMocks } from "./channels.mock-harness.js"; import { createMSTeamsCatalogEntry, @@ -14,6 +13,8 @@ import { } from "./channels.plugin-install.test-helpers.js"; import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js"; +let channelsRemoveCommand: typeof import("./channels.js").channelsRemoveCommand; + const catalogMocks = vi.hoisted(() => ({ listChannelPluginCatalogEntries: vi.fn((): ChannelPluginCatalogEntry[] => []), })); @@ -40,6 +41,10 @@ vi.mock("./channel-setup/plugin-install.js", async () => { const runtime = createTestRuntime(); describe("channelsRemoveCommand", () => { + beforeAll(async () => { + ({ channelsRemoveCommand } = await import("./channels.js")); + }); + beforeEach(() => { configMocks.readConfigFileSnapshot.mockClear(); configMocks.writeConfigFile.mockClear();