test: avoid extension count filter predicates · openclaw/openclaw@2c7f2d3
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -393,9 +393,7 @@ describe("Codex plugin thread config", () => {
|
393 | 393 | }); |
394 | 394 | expect(config.diagnostics).toEqual([]); |
395 | 395 | expect(request.mock.calls.map(([method]) => method)).toContain("plugin/install"); |
396 | | -expect(request.mock.calls.filter(([method]) => method === "app/list").length).toBeGreaterThan( |
397 | | -0, |
398 | | -); |
| 396 | +expect(request.mock.calls.some(([method]) => method === "app/list")).toBe(true); |
399 | 397 | expect(appListParams.map((params) => params.forceRefetch)).toContain(true); |
400 | 398 | }); |
401 | 399 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -46,6 +46,16 @@ const mockReaddirSync = vi.fn();
|
46 | 46 | const mockSettingsExistsSync = vi.fn(); |
47 | 47 | const mockSettingsReadFileSync = vi.fn(); |
48 | 48 | |
| 49 | +function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number { |
| 50 | +let count = 0; |
| 51 | +for (const item of items) { |
| 52 | +if (predicate(item)) { |
| 53 | +count += 1; |
| 54 | +} |
| 55 | +} |
| 56 | +return count; |
| 57 | +} |
| 58 | + |
49 | 59 | describe("resolveGeminiCliSelectedAuthType", () => { |
50 | 60 | const ENV_KEYS = ["GOOGLE_GENAI_USE_GCA"] as const; |
51 | 61 | |
@@ -843,7 +853,7 @@ describe("loginGeminiCliOAuth", () => {
|
843 | 853 | }); |
844 | 854 | |
845 | 855 | await runProjectDiscoveryExpectingProjectId("env-project"); |
846 | | -expect(requests.filter(({ url }) => url.includes("v1internal:loadCodeAssist"))).toHaveLength(3); |
| 856 | +expect(countMatching(requests, ({ url }) => url.includes("v1internal:loadCodeAssist"))).toBe(3); |
847 | 857 | expect(requests.map(({ url }) => url)).not.toEqual( |
848 | 858 | expect.arrayContaining([expect.stringContaining("v1internal:onboardUser")]), |
849 | 859 | ); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -128,7 +128,9 @@ describe("syncMemoryWikiBridgeSources", () => {
|
128 | 128 | expect(first.pagePaths).toHaveLength(3); |
129 | 129 | |
130 | 130 | const sourcePages = await fs.readdir(path.join(vaultDir, "sources")); |
131 | | -expect(sourcePages.filter((name) => name.startsWith("bridge-"))).toHaveLength(3); |
| 131 | +expect( |
| 132 | +sourcePages.reduce((count, name) => count + (name.startsWith("bridge-") ? 1 : 0), 0), |
| 133 | +).toBe(3); |
132 | 134 | |
133 | 135 | const memoryPage = await fs.readFile(path.join(vaultDir, first.pagePaths[0] ?? ""), "utf8"); |
134 | 136 | expect(memoryPage).toContain("sourceType: memory-bridge"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -45,6 +45,16 @@ function createContainerNetworkRunCommand(calls?: string[]) {
|
45 | 45 | }; |
46 | 46 | } |
47 | 47 | |
| 48 | +function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number { |
| 49 | +let count = 0; |
| 50 | +for (const item of items) { |
| 51 | +if (predicate(item)) { |
| 52 | +count += 1; |
| 53 | +} |
| 54 | +} |
| 55 | +return count; |
| 56 | +} |
| 57 | + |
48 | 58 | describe("matrix harness runtime", () => { |
49 | 59 | it("writes a pinned Tuwunel compose file and redacted manifest", async () => { |
50 | 60 | const outputDir = await mkdtemp(path.join(os.tmpdir(), "matrix-qa-harness-")); |
@@ -180,7 +190,7 @@ describe("matrix harness runtime", () => {
|
180 | 190 | return { |
181 | 191 | ok: |
182 | 192 | input === "http://127.0.0.1:28008/_matrix/client/versions" && |
183 | | -fetchCalls.filter((url) => url === input).length > 1, |
| 193 | +countMatching(fetchCalls, (url) => url === input) > 1, |
184 | 194 | }; |
185 | 195 | }), |
186 | 196 | sleepImpl: vi.fn(async () => {}), |
@@ -208,7 +218,7 @@ describe("matrix harness runtime", () => {
|
208 | 218 | return { |
209 | 219 | ok: |
210 | 220 | input === "http://172.18.0.10:8008/_matrix/client/versions" && |
211 | | -fetchCalls.filter((url) => url === input).length > 1, |
| 221 | +countMatching(fetchCalls, (url) => url === input) > 1, |
212 | 222 | }; |
213 | 223 | }), |
214 | 224 | sleepImpl: vi.fn(async () => {}), |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,16 @@ type TestLog = {
|
16 | 16 | error: (...args: unknown[]) => void; |
17 | 17 | }; |
18 | 18 | |
| 19 | +function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number { |
| 20 | +let count = 0; |
| 21 | +for (const item of items) { |
| 22 | +if (predicate(item)) { |
| 23 | +count += 1; |
| 24 | +} |
| 25 | +} |
| 26 | +return count; |
| 27 | +} |
| 28 | + |
19 | 29 | function makeAccount( |
20 | 30 | overrides: Partial<ResolvedSynologyChatAccount> = {}, |
21 | 31 | ): ResolvedSynologyChatAccount { |
@@ -240,8 +250,8 @@ describe("createWebhookHandler", () => {
|
240 | 250 | await new Promise((resolve) => setTimeout(resolve, 0)); |
241 | 251 | |
242 | 252 | // Default maxInFlightPerKey is 8; 12 total requests leaves 4 rejected with 429. |
243 | | -expect(responses.filter((res) => res._status === 0)).toHaveLength(8); |
244 | | -expect(responses.filter((res) => res._status === 429)).toHaveLength(4); |
| 253 | +expect(countMatching(responses, (res) => res._status === 0)).toBe(8); |
| 254 | +expect(countMatching(responses, (res) => res._status === 429)).toBe(4); |
245 | 255 | |
246 | 256 | for (const req of requests) { |
247 | 257 | req.emit("end"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。