test: avoid filtered map assertion allocations · openclaw/openclaw@17b1562
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -28,6 +28,20 @@ function cleanupDeps(processes: AcpxProcessInfo[]) {
|
28 | 28 | }; |
29 | 29 | } |
30 | 30 | |
| 31 | +function collectMatching<T, U>( |
| 32 | +items: readonly T[], |
| 33 | +predicate: (item: T) => boolean, |
| 34 | +map: (item: T) => U, |
| 35 | +): U[] { |
| 36 | +const matches: U[] = []; |
| 37 | +for (const item of items) { |
| 38 | +if (predicate(item)) { |
| 39 | +matches.push(map(item)); |
| 40 | +} |
| 41 | +} |
| 42 | +return matches; |
| 43 | +} |
| 44 | + |
31 | 45 | describe("process reaper", () => { |
32 | 46 | it("recognizes generated Codex and Claude wrappers only under the configured root", () => { |
33 | 47 | expect( |
@@ -237,9 +251,13 @@ describe("process reaper", () => {
|
237 | 251 | |
238 | 252 | expect(result.skippedReason).toBeUndefined(); |
239 | 253 | expect(result.inspectedPids).toEqual([400, 401, 402, 403, 404, 405]); |
240 | | -expect(killed.filter((entry) => entry.signal === "SIGTERM").map((entry) => entry.pid)).toEqual([ |
241 | | -402, 401, 400, 404, 403, 405, |
242 | | -]); |
| 254 | +expect( |
| 255 | +collectMatching( |
| 256 | +killed, |
| 257 | +(entry) => entry.signal === "SIGTERM", |
| 258 | +(entry) => entry.pid, |
| 259 | +), |
| 260 | +).toEqual([402, 401, 400, 404, 403, 405]); |
243 | 261 | }); |
244 | 262 | |
245 | 263 | it("keeps startup scans quiet when process listing is unavailable", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。