test: avoid extension filter count helpers · openclaw/openclaw@aa78d9e
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -35,6 +35,16 @@ function sendCdpResult(socket: WebSocket, id: number | undefined, result: Record
|
35 | 35 | socket.send(JSON.stringify({ id, result })); |
36 | 36 | } |
37 | 37 | |
| 38 | +function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number { |
| 39 | +let count = 0; |
| 40 | +for (const item of items) { |
| 41 | +if (predicate(item)) { |
| 42 | +count += 1; |
| 43 | +} |
| 44 | +} |
| 45 | +return count; |
| 46 | +} |
| 47 | + |
38 | 48 | function replyToPageEnable(msg: CdpMockMessage, socket: WebSocket): boolean { |
39 | 49 | if (msg.method !== "Page.enable") { |
40 | 50 | return false; |
@@ -197,7 +207,7 @@ describe("cdp internal", () => {
|
197 | 207 | } |
198 | 208 | if (msg.method === "Runtime.evaluate") { |
199 | 209 | // Pre-capture viewport probe + post-capture probe. |
200 | | -const isPre = events.filter((m) => m === "Runtime.evaluate").length === 1; |
| 210 | +const isPre = countMatching(events, (m) => m === "Runtime.evaluate") === 1; |
201 | 211 | socket.send( |
202 | 212 | JSON.stringify({ |
203 | 213 | id: msg.id, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -94,7 +94,7 @@ describe("matrix channel message adapter", () => {
|
94 | 94 | |
95 | 95 | const proveReplyThread = async () => { |
96 | 96 | mocks.sendMessageMatrix.mockClear(); |
97 | | -const result = await adapter.send.text({ |
| 97 | +const result = await sendText({ |
98 | 98 | cfg, |
99 | 99 | to: "room:!room:example", |
100 | 100 | text: "threaded", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,27 +9,17 @@ import {
|
9 | 9 | type TelegramChunk = ReturnType<typeof markdownToTelegramChunks>[number]; |
10 | 10 | |
11 | 11 | function expectHtmlChunkLengthsAtMost(chunks: TelegramChunk[], limit: number) { |
12 | | -expect( |
13 | | -chunks |
14 | | -.map((chunk, index) => ({ index, htmlLength: chunk.html.length, text: chunk.text })) |
15 | | -.filter((chunk) => chunk.htmlLength > limit), |
16 | | -).toEqual([]); |
| 12 | +expect(chunks.some((chunk) => chunk.html.length > limit)).toBe(false); |
17 | 13 | } |
18 | 14 | |
19 | 15 | function expectNonBlankTextChunks(chunks: TelegramChunk[]) { |
20 | | -expect( |
21 | | -chunks |
22 | | -.map((chunk, index) => ({ index, text: chunk.text })) |
23 | | -.filter((chunk) => chunk.text.trim().length === 0), |
24 | | -).toEqual([]); |
| 16 | +expect(chunks.some((chunk) => chunk.text.trim().length === 0)).toBe(false); |
25 | 17 | } |
26 | 18 | |
27 | 19 | function expectHtmlChunksWrappedWith(chunks: TelegramChunk[], prefix: string, suffix: string) { |
28 | 20 | expect( |
29 | | -chunks |
30 | | -.map((chunk, index) => ({ index, html: chunk.html })) |
31 | | -.filter((chunk) => !chunk.html.startsWith(prefix) || !chunk.html.endsWith(suffix)), |
32 | | -).toEqual([]); |
| 21 | +chunks.every((chunk) => chunk.html.startsWith(prefix) && chunk.html.endsWith(suffix)), |
| 22 | +).toBe(true); |
33 | 23 | } |
34 | 24 | |
35 | 25 | describe("wrapFileReferencesInHtml", () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。