

























@@ -96,6 +96,14 @@ function createCatalogEntry(id: string, label: string): ChannelPluginCatalogEntr
9696} as unknown as ChannelPluginCatalogEntry;
9797}
989899+function loggedText(runtime: ReturnType<typeof createTestRuntime>): string {
100+const value = runtime.log.mock.calls.at(0)?.[0];
101+if (typeof value !== "string") {
102+throw new Error("expected runtime log text");
103+}
104+return value;
105+}
106+99107describe("channels list", () => {
100108beforeEach(() => {
101109mocks.readConfigFileSnapshot.mockReset();
@@ -118,7 +126,7 @@ describe("channels list", () => {
118126119127await channelsListCommand({ json: true }, runtime);
120128121-const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as Record<string, unknown>;
129+const payload = JSON.parse(loggedText(runtime)) as Record<string, unknown>;
122130expect(payload.auth).toBeUndefined();
123131expect(payload).toHaveProperty("chat");
124132});
@@ -148,7 +156,7 @@ describe("channels list", () => {
148156expect(mocks.listReadOnlyChannelPluginsForConfig).toHaveBeenCalledWith(config, {
149157includeSetupFallbackPlugins: true,
150158});
151-const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
159+const payload = JSON.parse(loggedText(runtime)) as {
152160chat?: Record<string, { accounts: string[]; installed: boolean; origin: string }>;
153161};
154162expect(payload.chat?.telegram).toEqual({
@@ -167,7 +175,7 @@ describe("channels list", () => {
167175168176await channelsListCommand({ json: true }, runtime);
169177170-const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
178+const payload = JSON.parse(loggedText(runtime)) as {
171179usage?: unknown;
172180};
173181expect(payload.usage).toBeUndefined();
@@ -204,7 +212,7 @@ describe("channels list", () => {
204212expect(mocks.listReadOnlyChannelPluginsForConfig).toHaveBeenCalledWith(config, {
205213includeSetupFallbackPlugins: true,
206214});
207-const output = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
215+const output = stripAnsi(loggedText(runtime));
208216expect(output).toContain("Chat channels:");
209217expect(output).toContain("Telegram default:");
210218expect(output).toContain("installed");
@@ -227,7 +235,7 @@ describe("channels list", () => {
227235228236await channelsListCommand({}, runtime);
229237230-const output = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
238+const output = stripAnsi(loggedText(runtime));
231239expect(output).toContain("Chat channels:");
232240expect(output).not.toContain("QQ Bot");
233241// Hint user about --all
@@ -248,7 +256,7 @@ describe("channels list", () => {
248256249257await channelsListCommand({ all: true }, runtime);
250258251-const output = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
259+const output = stripAnsi(loggedText(runtime));
252260expect(output).toContain("QQ Bot");
253261expect(output).toContain("not installed");
254262expect(output).toContain("not configured");
@@ -271,14 +279,14 @@ describe("channels list", () => {
271279272280// Without --all: discord should not appear.
273281await channelsListCommand({}, runtime);
274-const noAllOutput = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
282+const noAllOutput = stripAnsi(loggedText(runtime));
275283expect(noAllOutput).not.toContain("Discord default:");
276284277285runtime.log.mockClear();
278286279287// With --all: discord is rendered with installed + not configured + disabled.
280288await channelsListCommand({ all: true }, runtime);
281-const allOutput = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
289+const allOutput = stripAnsi(loggedText(runtime));
282290expect(allOutput).toContain("Discord default:");
283291expect(allOutput).toContain("installed");
284292expect(allOutput).toContain("not configured");
@@ -311,7 +319,7 @@ describe("channels list", () => {
311319312320await channelsListCommand({ json: true, all: true }, runtime);
313321314-const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
322+const payload = JSON.parse(loggedText(runtime)) as {
315323chat: Record<string, { origin: string; installed: boolean }>;
316324};
317325expect(payload.chat.telegram?.origin).toBe("configured");
@@ -344,7 +352,7 @@ describe("channels list", () => {
344352345353await channelsListCommand({ all: true }, runtime);
346354347-const output = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
355+const output = stripAnsi(loggedText(runtime));
348356expect(output).toContain("WeCom");
349357expect(output).toContain("installed");
350358expect(output).not.toContain("not installed");
@@ -355,7 +363,7 @@ describe("channels list", () => {
355363// not written a config entry for it).
356364runtime.log.mockClear();
357365await channelsListCommand({ json: true, all: true }, runtime);
358-const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
366+const payload = JSON.parse(loggedText(runtime)) as {
359367chat: Record<string, { origin: string; installed: boolean }>;
360368};
361369expect(payload.chat.wecom?.origin).toBe("available");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。