test: avoid cli count filter allocations · openclaw/openclaw@9803a96
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -173,8 +173,10 @@ describe("command-registry", () => {
|
173 | 173 | } |
174 | 174 | |
175 | 175 | const names = namesOf(program); |
176 | | -expect(names.filter((name) => name === "commitments")).toHaveLength(1); |
177 | | -expect(names.filter((name) => name === "tasks")).toHaveLength(1); |
| 176 | +const countName = (target: string) => |
| 177 | +names.reduce((count, name) => count + (name === target ? 1 : 0), 0); |
| 178 | +expect(countName("commitments")).toBe(1); |
| 179 | +expect(countName("tasks")).toBe(1); |
178 | 180 | }); |
179 | 181 | |
180 | 182 | it("replaces placeholders when loading a grouped entry by secondary command name", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -192,7 +192,7 @@ describe("registerSubCliCommands", () => {
|
192 | 192 | await registerSubCliByName(program, "acp"); |
193 | 193 | |
194 | 194 | const names = program.commands.map((cmd) => cmd.name()); |
195 | | -expect(names.filter((name) => name === "acp")).toHaveLength(1); |
| 195 | +expect(names.reduce((count, name) => count + (name === "acp" ? 1 : 0), 0)).toBe(1); |
196 | 196 | |
197 | 197 | await program.parseAsync(["acp"], { from: "user" }); |
198 | 198 | expect(registerAcpCli).toHaveBeenCalledTimes(1); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -397,7 +397,9 @@ describe("registerPluginCliCommands", () => {
|
397 | 397 | primary: "memory", |
398 | 398 | }); |
399 | 399 | |
400 | | -expect(program.commands.filter((command) => command.name() === "memory")).toHaveLength(1); |
| 400 | +expect( |
| 401 | +program.commands.reduce((count, command) => count + (command.name() === "memory" ? 1 : 0), 0), |
| 402 | +).toBe(1); |
401 | 403 | expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith( |
402 | 404 | expect.objectContaining({ |
403 | 405 | onlyPluginIds: ["memory-core"], |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。