test: avoid misc count filter allocations · openclaw/openclaw@ce515db
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -73,7 +73,7 @@ describe("replayRecentUserAssistantMessages", () => {
|
73 | 73 | .split(/\r?\n/) |
74 | 74 | .filter((line) => line.trim().length > 0) |
75 | 75 | .map((line) => JSON.parse(line)); |
76 | | -expect(records.filter((r) => r.type === "session")).toHaveLength(1); |
| 76 | +expect(records.reduce((count, r) => count + (r.type === "session" ? 1 : 0), 0)).toBe(1); |
77 | 77 | expect(records[0]).toMatchObject({ id: "existing" }); |
78 | 78 | expect(records[1].message.role).toBe("user"); |
79 | 79 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -582,7 +582,12 @@ describe("runCli exit behavior", () => {
|
582 | 582 | try { |
583 | 583 | const runPromise = runCli(["node", "openclaw", "plugins", "marketplace", "list"]); |
584 | 584 | await vi.waitFor(() => { |
585 | | -expect(processOnceSpy.mock.calls.filter(([event]) => event === "exit")).toHaveLength(2); |
| 585 | +expect( |
| 586 | +processOnceSpy.mock.calls.reduce( |
| 587 | +(count, [event]) => count + (event === "exit" ? 1 : 0), |
| 588 | +0, |
| 589 | +), |
| 590 | +).toBe(2); |
586 | 591 | }); |
587 | 592 | |
588 | 593 | const exitHandler = processOnceSpy.mock.calls.find(([event]) => event === "exit")?.[1]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -585,7 +585,9 @@ describe("modelsStatusCommand auth overview", () => {
|
585 | 585 | await modelsStatusCommand({ json: true }, aliasRuntime as never); |
586 | 586 | const aliasPayload = JSON.parse(String((aliasRuntime.log as Mock).mock.calls[0]?.[0])); |
587 | 587 | const providers = aliasPayload.auth.providers as Array<{ provider: string }>; |
588 | | -expect(providers.filter((provider) => provider.provider === "zai")).toHaveLength(1); |
| 588 | +expect( |
| 589 | +providers.reduce((count, provider) => count + (provider.provider === "zai" ? 1 : 0), 0), |
| 590 | +).toBe(1); |
589 | 591 | expect(providers.map((provider) => provider.provider)).not.toContain("z.ai"); |
590 | 592 | } finally { |
591 | 593 | if (originalLoadConfig) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -294,7 +294,7 @@ describeLaunchdIntegration("launchd integration", () => {
|
294 | 294 | }); |
295 | 295 | const events = await fs.readFile(eventsPath, "utf8"); |
296 | 296 | const lines = events.trim().split(/\r?\n/).filter(Boolean); |
297 | | -expect(lines.filter((line) => line.startsWith("start "))).toHaveLength(1); |
| 297 | +expect(lines.reduce((count, line) => count + (line.startsWith("start ") ? 1 : 0), 0)).toBe(1); |
298 | 298 | const signalLines = lines.filter((line) => /^(SIGHUP|SIGINT|SIGTERM) /.test(line)); |
299 | 299 | expect(signalLines).toEqual([]); |
300 | 300 | }, 60_000); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -631,7 +631,9 @@ describe("gateway broadcaster", () => {
|
631 | 631 | reason: "ws_send_buffer_drop", |
632 | 632 | }), |
633 | 633 | ); |
634 | | -expect(events.filter((event) => event.type === "payload.large")).toHaveLength(1); |
| 634 | +expect( |
| 635 | +events.reduce((count, event) => count + (event.type === "payload.large" ? 1 : 0), 0), |
| 636 | +).toBe(1); |
635 | 637 | } finally { |
636 | 638 | stop(); |
637 | 639 | resetDiagnosticEventsForTest(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -149,6 +149,11 @@ describe("diagnostic memory", () => {
|
149 | 149 | } |
150 | 150 | stop(); |
151 | 151 | |
152 | | -expect(events.filter((event) => event.type === "diagnostic.memory.pressure")).toHaveLength(1); |
| 152 | +expect( |
| 153 | +events.reduce( |
| 154 | +(count, event) => count + (event.type === "diagnostic.memory.pressure" ? 1 : 0), |
| 155 | +0, |
| 156 | +), |
| 157 | +).toBe(1); |
153 | 158 | }); |
154 | 159 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -135,8 +135,10 @@ describe("createClaimableDedupe", () => {
|
135 | 135 | await expect(dedupe.claim("line:evt-1")).resolves.toEqual({ kind: "duplicate" }); |
136 | 136 | |
137 | 137 | const claims = await Promise.all([dedupe.claim("line:race-1"), dedupe.claim("line:race-1")]); |
138 | | -expect(claims.filter((claim) => claim.kind === "claimed")).toHaveLength(1); |
139 | | -expect(claims.filter((claim) => claim.kind === "inflight")).toHaveLength(1); |
| 138 | +const countClaimKind = (kind: (typeof claims)[number]["kind"]) => |
| 139 | +claims.reduce((count, claim) => count + (claim.kind === kind ? 1 : 0), 0); |
| 140 | +expect(countClaimKind("claimed")).toBe(1); |
| 141 | +expect(countClaimKind("inflight")).toBe(1); |
140 | 142 | |
141 | 143 | const waitingClaim = claims.find((claim) => claim.kind === "inflight"); |
142 | 144 | await expect(dedupe.commit("line:race-1")).resolves.toBe(true); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -150,7 +150,7 @@ describe("plugin state keyed store", () => {
|
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | |
153 | | -expect(attempts.filter(Boolean)).toHaveLength(1); |
| 153 | +expect(attempts.reduce((count, attempt) => count + (attempt ? 1 : 0), 0)).toBe(1); |
154 | 154 | const stored = await store.lookup("claim"); |
155 | 155 | if (stored === undefined) { |
156 | 156 | throw new Error("expected winning plugin-state claim"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1226,7 +1226,7 @@ describe("tui-event-handlers: streaming watchdog", () => {
|
1226 | 1226 | vi.advanceTimersByTime(10_000); |
1227 | 1227 | |
1228 | 1228 | const statusCalls = setActivityStatus.mock.calls.map((c) => c[0]); |
1229 | | -expect(statusCalls.filter((s) => s === "idle").length).toBe(1); |
| 1229 | +expect(statusCalls.reduce((count, s) => count + (s === "idle" ? 1 : 0), 0)).toBe(1); |
1230 | 1230 | expect(chatLog.addSystem).not.toHaveBeenCalledWith(expectedTimeoutMessage); |
1231 | 1231 | expect(state.activeChatRunId).toBeNull(); |
1232 | 1232 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -60,10 +60,10 @@ describe("scripts/lib/docker-e2e-plan", () => {
|
60 | 60 | expect(plan.lanes.map((lane) => lane.name)).toContain("commitments-safety"); |
61 | 61 | expect(plan.lanes.map((lane) => lane.name)).toContain("bundled-plugin-install-uninstall-0"); |
62 | 62 | expect(plan.lanes.map((lane) => lane.name)).toContain("bundled-plugin-install-uninstall-23"); |
63 | | -expect(plan.lanes.filter((lane) => lane.name === "install-e2e-openai")).toHaveLength(1); |
64 | | -expect( |
65 | | - plan.lanes.filter((lane) => lane.name === "bundled-plugin-install-uninstall-0"), |
66 | | -).toHaveLength(1); |
| 63 | +const countLane = (name: string) => |
| 64 | + plan.lanes.reduce((count, lane) => count + (lane.name === name ? 1 : 0), 0); |
| 65 | +expect(countLane("install-e2e-openai")).toBe(1); |
| 66 | +expect(countLane("bundled-plugin-install-uninstall-0")).toBe(1); |
67 | 67 | expect(plan.lanes.map((lane) => lane.name)).not.toContain("bundled-plugin-install-uninstall"); |
68 | 68 | expect(plan.lanes.map((lane) => lane.name)).not.toContain("bundled-channel-deps"); |
69 | 69 | expect(plan.lanes.map((lane) => lane.name)).not.toContain("openwebui"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。