Skip to content

Commit ac5a54e

Browse files
authored
test(adapters): adopt shared @chat-adapter/tests factories and matchers (#674)
Wires `@chat-adapter/tests` as a devDependency and registers its matchers via `setupFiles: ["@chat-adapter/tests/setup"]` across all 11 platform adapters, then replaces bespoke local `mockLogger`/`createMockState`/`createMockChatInstance` with the shared factories and adopts `toHaveDispatched`/`not.toHaveDispatched` where clean. - 10 adapters migrated (gchat, messenger, teams, whatsapp, telegram, discord, twilio, linear, github, slack). Positional `createMockChatInstance(...)` call sites converted to the options API (slack 100, linear 35). - `web` left as-is — its suite uses the real `Chat`/`createMemoryState` for e2e, so the shared factories don't apply. - Platform SDK mocks (Octokit, WebClient, socket-mode, `@linear/sdk`, `fetch`) and the Phase 1 `connectWebhookContract` descriptors are left intact. Net ~−540 lines of duplicated test scaffolding. Stacked on #673. Tests-only, no changeset. --------- Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com> Co-authored-by: Ben Sabic <bensabic@users.noreply.github.com>
1 parent 840c0d1 commit ac5a54e

32 files changed

Lines changed: 439 additions & 934 deletions

packages/adapter-discord/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"discord.js": "^14.25.1"
3535
},
3636
"devDependencies": {
37+
"@chat-adapter/tests": "workspace:*",
3738
"@types/node": "^25.3.2",
3839
"tsup": "^8.3.5",
3940
"typescript": "^5.7.2",

packages/adapter-discord/src/gateway.test.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* intents and partials for receiving DM events.
66
*/
77

8+
import { createMockChatInstance, mockLogger } from "@chat-adapter/tests";
89
import { GatewayIntentBits, Partials } from "discord.js";
910
import { describe, expect, it, vi } from "vitest";
1011
import { createDiscordAdapter } from "./index";
@@ -33,30 +34,6 @@ vi.mock("discord.js", async () => {
3334
};
3435
});
3536

36-
const mockLogger = {
37-
debug: vi.fn(),
38-
info: vi.fn(),
39-
warn: vi.fn(),
40-
error: vi.fn(),
41-
child: vi.fn().mockReturnThis(),
42-
};
43-
44-
const mockChat = {
45-
getLogger: vi.fn().mockReturnValue(mockLogger),
46-
getState: vi.fn(),
47-
getUserName: vi.fn().mockReturnValue("bot"),
48-
handleIncomingMessage: vi.fn(),
49-
processAction: vi.fn(),
50-
processOptionsLoad: vi.fn().mockResolvedValue(undefined),
51-
processAppHomeOpened: vi.fn(),
52-
processAssistantContextChanged: vi.fn(),
53-
processAssistantThreadStarted: vi.fn(),
54-
processMessage: vi.fn(),
55-
processModalClose: vi.fn(),
56-
processModalSubmit: vi.fn(),
57-
processReaction: vi.fn(),
58-
};
59-
6037
describe("Gateway client configuration", () => {
6138
it("includes Partials.Channel for DM support", async () => {
6239
MockClient.mockClear();
@@ -71,7 +48,7 @@ describe("Gateway client configuration", () => {
7148
logger: mockLogger,
7249
});
7350

74-
await adapter.initialize(mockChat as never);
51+
await adapter.initialize(createMockChatInstance());
7552

7653
// Use a pre-aborted signal so the listener resolves immediately
7754
const controller = new AbortController();

0 commit comments

Comments
 (0)