diff --git a/extensions/discord/index.test.ts b/extensions/discord/index.test.ts index 695047d1ada..07f5cd173db 100644 --- a/extensions/discord/index.test.ts +++ b/extensions/discord/index.test.ts @@ -1,16 +1,13 @@ -import { describe, expect, it } from "vitest"; +import { describe } from "vitest"; +import { assertBundledChannelEntries } from "../../test/helpers/bundled-channel-entry.ts"; import entry from "./index.js"; import setupEntry from "./setup-entry.js"; describe("discord bundled entries", () => { - it("declares the channel plugin without importing the broad api barrel", () => { - expect(entry.kind).toBe("bundled-channel-entry"); - expect(entry.id).toBe("discord"); - expect(entry.name).toBe("Discord"); - }); - - it("declares the setup plugin without importing the broad api barrel", () => { - expect(setupEntry.kind).toBe("bundled-channel-setup-entry"); - expect(typeof setupEntry.loadSetupPlugin).toBe("function"); + assertBundledChannelEntries({ + entry, + expectedId: "discord", + expectedName: "Discord", + setupEntry, }); }); diff --git a/extensions/irc/index.test.ts b/extensions/irc/index.test.ts index e59d1be2a82..5149616f867 100644 --- a/extensions/irc/index.test.ts +++ b/extensions/irc/index.test.ts @@ -1,16 +1,13 @@ -import { describe, expect, it } from "vitest"; +import { describe } from "vitest"; +import { assertBundledChannelEntries } from "../../test/helpers/bundled-channel-entry.ts"; import entry from "./index.js"; import setupEntry from "./setup-entry.js"; describe("irc bundled entries", () => { - it("declares the channel plugin without importing the broad api barrel", () => { - expect(entry.kind).toBe("bundled-channel-entry"); - expect(entry.id).toBe("irc"); - expect(entry.name).toBe("IRC"); - }); - - it("declares the setup plugin without importing the broad api barrel", () => { - expect(setupEntry.kind).toBe("bundled-channel-setup-entry"); - expect(typeof setupEntry.loadSetupPlugin).toBe("function"); + assertBundledChannelEntries({ + entry, + expectedId: "irc", + expectedName: "IRC", + setupEntry, }); }); diff --git a/extensions/slack/index.test.ts b/extensions/slack/index.test.ts index dfd9d393973..bdef1336697 100644 --- a/extensions/slack/index.test.ts +++ b/extensions/slack/index.test.ts @@ -1,16 +1,13 @@ -import { describe, expect, it } from "vitest"; +import { describe } from "vitest"; +import { assertBundledChannelEntries } from "../../test/helpers/bundled-channel-entry.ts"; import entry from "./index.js"; import setupEntry from "./setup-entry.js"; describe("slack bundled entries", () => { - it("declares the channel plugin without importing the broad api barrel", () => { - expect(entry.kind).toBe("bundled-channel-entry"); - expect(entry.id).toBe("slack"); - expect(entry.name).toBe("Slack"); - }); - - it("declares the setup plugin without importing the broad api barrel", () => { - expect(setupEntry.kind).toBe("bundled-channel-setup-entry"); - expect(typeof setupEntry.loadSetupPlugin).toBe("function"); + assertBundledChannelEntries({ + entry, + expectedId: "slack", + expectedName: "Slack", + setupEntry, }); }); diff --git a/extensions/telegram/index.test.ts b/extensions/telegram/index.test.ts index b7811553c4b..fcf9094dedb 100644 --- a/extensions/telegram/index.test.ts +++ b/extensions/telegram/index.test.ts @@ -1,4 +1,5 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, vi } from "vitest"; +import { assertBundledChannelEntries } from "../../test/helpers/bundled-channel-entry.ts"; import entry from "./index.js"; import setupEntry from "./setup-entry.js"; @@ -7,13 +8,11 @@ describe("telegram bundled entries", () => { vi.useRealTimers(); }); - it("declares the channel entry without importing the broad api barrel", () => { - expect(entry.id).toBe("telegram"); - expect(entry.name).toBe("Telegram"); - }); - - it("declares the setup plugin without importing the broad api barrel", () => { - expect(setupEntry.kind).toBe("bundled-channel-setup-entry"); - expect(typeof setupEntry.loadSetupPlugin).toBe("function"); + assertBundledChannelEntries({ + entry, + expectedId: "telegram", + expectedName: "Telegram", + setupEntry, + channelMessage: "declares the channel entry without importing the broad api barrel", }); }); diff --git a/extensions/whatsapp/index.test.ts b/extensions/whatsapp/index.test.ts index 22fd4f4540d..c5e2c4a5836 100644 --- a/extensions/whatsapp/index.test.ts +++ b/extensions/whatsapp/index.test.ts @@ -1,16 +1,13 @@ -import { describe, expect, it } from "vitest"; +import { describe } from "vitest"; +import { assertBundledChannelEntries } from "../../test/helpers/bundled-channel-entry.ts"; import entry from "./index.js"; import setupEntry from "./setup-entry.js"; describe("whatsapp bundled entries", () => { - it("declares the channel plugin without importing the broad api barrel", () => { - expect(entry.kind).toBe("bundled-channel-entry"); - expect(entry.id).toBe("whatsapp"); - expect(entry.name).toBe("WhatsApp"); - }); - - it("declares the setup plugin without importing the broad api barrel", () => { - expect(setupEntry.kind).toBe("bundled-channel-setup-entry"); - expect(typeof setupEntry.loadSetupPlugin).toBe("function"); + assertBundledChannelEntries({ + entry, + expectedId: "whatsapp", + expectedName: "WhatsApp", + setupEntry, }); }); diff --git a/extensions/zalo/index.test.ts b/extensions/zalo/index.test.ts index 65d2a709c30..d52d43e7cb1 100644 --- a/extensions/zalo/index.test.ts +++ b/extensions/zalo/index.test.ts @@ -1,16 +1,15 @@ -import { describe, expect, it } from "vitest"; +import { describe } from "vitest"; +import { assertBundledChannelEntries } from "../../test/helpers/bundled-channel-entry.ts"; import entry from "./index.js"; import setupEntry from "./setup-entry.js"; describe("zalo bundled entries", () => { - it("declares the channel plugin without a runtime-barrel cycle", () => { - expect(entry.kind).toBe("bundled-channel-entry"); - expect(entry.id).toBe("zalo"); - expect(entry.name).toBe("Zalo"); - }); - - it("declares the setup plugin without a runtime-barrel cycle", () => { - expect(setupEntry.kind).toBe("bundled-channel-setup-entry"); - expect(typeof setupEntry.loadSetupPlugin).toBe("function"); + assertBundledChannelEntries({ + entry, + expectedId: "zalo", + expectedName: "Zalo", + setupEntry, + channelMessage: "declares the channel plugin without a runtime-barrel cycle", + setupMessage: "declares the setup plugin without a runtime-barrel cycle", }); }); diff --git a/test/helpers/bundled-channel-entry.ts b/test/helpers/bundled-channel-entry.ts new file mode 100644 index 00000000000..26660b13b93 --- /dev/null +++ b/test/helpers/bundled-channel-entry.ts @@ -0,0 +1,38 @@ +import { expect, it } from "vitest"; + +type BundledChannelEntry = { + id: string; + kind?: string; + name: string; +}; + +type BundledChannelSetupEntry = { + kind?: string; + loadSetupPlugin?: unknown; +}; + +export function assertBundledChannelEntries(params: { + entry: BundledChannelEntry; + expectedId: string; + expectedName: string; + setupEntry: BundledChannelSetupEntry; + channelMessage?: string; + setupMessage?: string; +}) { + it( + params.channelMessage ?? "declares the channel plugin without importing the broad api barrel", + () => { + expect(params.entry.kind).toBe("bundled-channel-entry"); + expect(params.entry.id).toBe(params.expectedId); + expect(params.entry.name).toBe(params.expectedName); + }, + ); + + it( + params.setupMessage ?? "declares the setup plugin without importing the broad api barrel", + () => { + expect(params.setupEntry.kind).toBe("bundled-channel-setup-entry"); + expect(typeof params.setupEntry.loadSetupPlugin).toBe("function"); + }, + ); +}