test: guard core mock call reads · openclaw/openclaw@ccce9aa
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,7 +47,11 @@ function requireRecord(value: unknown): Record<string, unknown> {
|
47 | 47 | } |
48 | 48 | |
49 | 49 | function firstMockArg(mock: ReturnType<typeof vi.fn>): Record<string, unknown> { |
50 | | -return requireRecord(mock.mock.calls[0]?.[0]); |
| 50 | +const [call] = mock.mock.calls; |
| 51 | +if (!call) { |
| 52 | +throw new Error("Expected mock to be called"); |
| 53 | +} |
| 54 | +return requireRecord(call[0]); |
51 | 55 | } |
52 | 56 | |
53 | 57 | describe("Crestodian assistant", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,14 @@ import {
|
13 | 13 | shouldEnableOpenClawCompileCache, |
14 | 14 | } from "./entry.compile-cache.js"; |
15 | 15 | |
| 16 | +function requireFirstMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] { |
| 17 | +const [call] = mock.mock.calls; |
| 18 | +if (!call) { |
| 19 | +throw new Error(`expected ${label} call`); |
| 20 | +} |
| 21 | +return call; |
| 22 | +} |
| 23 | + |
16 | 24 | describe("entry compile cache", () => { |
17 | 25 | const tempDirs: string[] = []; |
18 | 26 | |
@@ -155,9 +163,12 @@ describe("entry compile cache", () => {
|
155 | 163 | env: { NODE_DISABLE_COMPILE_CACHE: "1" }, |
156 | 164 | }, |
157 | 165 | ); |
158 | | -expect(attachChildProcessBridge.mock.calls[0]?.[0]).toBe(child); |
159 | | -const bridgeOptions = attachChildProcessBridge.mock.calls[0]?.[1]; |
160 | | -expect(typeof bridgeOptions?.onSignal).toBe("function"); |
| 166 | +const [bridgeChild, bridgeOptions] = requireFirstMockCall( |
| 167 | +attachChildProcessBridge, |
| 168 | +"child process bridge attach", |
| 169 | +); |
| 170 | +expect(bridgeChild).toBe(child); |
| 171 | +expect(bridgeOptions).toEqual(expect.objectContaining({ onSignal: expect.any(Function) })); |
161 | 172 | |
162 | 173 | child.emit("exit", 0, null); |
163 | 174 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -28,7 +28,11 @@ describe("diagnostic-events", () => {
|
28 | 28 | |
29 | 29 | function expectConsoleErrorPrefix(errorSpy: { mock: { calls: unknown[][] } }, prefix: string) { |
30 | 30 | expect(errorSpy.mock.calls).toHaveLength(1); |
31 | | -const message = errorSpy.mock.calls[0]?.[0]; |
| 31 | +const [call] = errorSpy.mock.calls; |
| 32 | +if (!call) { |
| 33 | +throw new Error("expected console error call"); |
| 34 | +} |
| 35 | +const [message] = call; |
32 | 36 | expect(typeof message).toBe("string"); |
33 | 37 | expect((message as string).startsWith(prefix)).toBe(true); |
34 | 38 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。