Skip to content

Commit f09ecb3

Browse files
author
Kai Liu
committed
test(slack/api): preserve real exports through mock.module stub
The previous mock.module factory only returned getApp + getSlackBotToken, so when later test files in the same Bun process imported other exports from packages/ims/slack/client (e.g. sendChannelMessage in packages/core/tasks/scheduler.ts and packages/core/test/web-routes.test.ts), Bun resolved them against the stub and threw: SyntaxError: Export named 'sendChannelMessage' not found in module '/home/runner/work/ode/ode/packages/ims/slack/client.ts' Locally test ordering hid this; CI's alphabetic ordering surfaced it as 2 failed tests / 2 unhandled errors in fast-checks. Fix: load the real ./client first and spread its exports into the stub before overriding getApp + getSlackBotToken. Downstream importers in the same process now still see every real export.
1 parent 823ed9d commit f09ecb3

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/ims/slack/api.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
44
// the single `./client` module so we don't need a real Slack connection,
55
// and expose both the raw `apiCall` surface (used by the streaming helpers)
66
// and the typed `chat.postMessage` surface (used by `postSlackQuestion`).
7+
//
8+
// IMPORTANT: `mock.module(...)` is process-wide in Bun, so the stub stays in
9+
// place for every later test file that loads `./client`. To avoid breaking
10+
// downstream tests that pull other exports (e.g. `sendChannelMessage` used by
11+
// `packages/core/tasks/scheduler.ts` and `packages/core/test/web-routes.test.ts`),
12+
// we start from the real module's exports and only override `getApp` /
13+
// `getSlackBotToken`. This way later imports keep finding every real export.
714
const apiCalls: Array<{ method: string; args: Record<string, unknown> }> = [];
815
const postMessageCalls: Array<Record<string, unknown>> = [];
916

17+
const realClient = await import("./client");
18+
1019
mock.module("./client", () => ({
20+
...realClient,
1121
getApp: () => ({
1222
client: {
1323
apiCall: async (method: string, args: Record<string, unknown>) => {
@@ -22,8 +32,8 @@ mock.module("./client", () => ({
2232
},
2333
},
2434
}),
25-
// `postSlackQuestion` does not call getSlackBotToken; we still export it
26-
// so the module load doesn't fail when ./api re-imports it.
35+
// Override so the test never accidentally picks up a stale workspace token
36+
// during the test run.
2737
getSlackBotToken: () => "xoxb-test",
2838
}));
2939

0 commit comments

Comments
 (0)