Tests: load channel command mocks before subjects

This commit is contained in:
Peter Steinberger
2026-04-07 10:01:37 +01:00
parent ba484d263b
commit 5b5018bac5
2 changed files with 14 additions and 4 deletions

View File

@@ -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();

View File

@@ -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();