Skip to content

Commit a474a9c

Browse files
committed
test: reuse feishu streaming merge helper
1 parent b6c297a commit a474a9c

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

extensions/feishu/src/reply-dispatcher.test.ts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,27 @@ vi.mock("./typing.js", () => ({
2525
addTypingIndicator: addTypingIndicatorMock,
2626
removeTypingIndicator: removeTypingIndicatorMock,
2727
}));
28-
vi.mock("./streaming-card.js", () => ({
29-
mergeStreamingText: (previousText: string | undefined, nextText: string | undefined) => {
30-
const previous = typeof previousText === "string" ? previousText : "";
31-
const next = typeof nextText === "string" ? nextText : "";
32-
if (!next) {
33-
return previous;
34-
}
35-
if (!previous || next === previous) {
36-
return next;
37-
}
38-
if (next.startsWith(previous)) {
39-
return next;
40-
}
41-
if (previous.startsWith(next)) {
42-
return previous;
43-
}
44-
return `${previous}${next}`;
45-
},
46-
FeishuStreamingSession: class {
47-
active = false;
48-
start = vi.fn(async () => {
49-
this.active = true;
50-
});
51-
update = vi.fn(async () => {});
52-
close = vi.fn(async () => {
53-
this.active = false;
54-
});
55-
isActive = vi.fn(() => this.active);
56-
57-
constructor() {
58-
streamingInstances.push(this);
59-
}
60-
},
61-
}));
28+
vi.mock("./streaming-card.js", async () => {
29+
const actual = await vi.importActual<typeof import("./streaming-card.js")>("./streaming-card.js");
30+
return {
31+
mergeStreamingText: actual.mergeStreamingText,
32+
FeishuStreamingSession: class {
33+
active = false;
34+
start = vi.fn(async () => {
35+
this.active = true;
36+
});
37+
update = vi.fn(async () => {});
38+
close = vi.fn(async () => {
39+
this.active = false;
40+
});
41+
isActive = vi.fn(() => this.active);
42+
43+
constructor() {
44+
streamingInstances.push(this);
45+
}
46+
},
47+
};
48+
});
6249

6350
import { createFeishuReplyDispatcher } from "./reply-dispatcher.js";
6451

0 commit comments

Comments
 (0)