




























@@ -56,13 +56,18 @@ function expectRecordFields(record: unknown, expected: Record<string, unknown>)
5656}
57575858function mockCallArg(mock: ReturnType<typeof vi.fn>, callIndex = 0, argIndex = 0) {
59-const call = mock.mock.calls[callIndex];
59+const resolvedIndex = callIndex < 0 ? mock.mock.calls.length + callIndex : callIndex;
60+const call = mock.mock.calls[resolvedIndex];
6061if (!call) {
6162throw new Error(`Expected mock call ${callIndex}`);
6263}
6364return call[argIndex];
6465}
656667+function stdoutWriteArg(callIndex = -1) {
68+return mockCallArg(stdoutWriteMock, callIndex);
69+}
70+6671vi.mock("./matrix/actions/verification.js", () => ({
6772acceptMatrixVerification: (...args: unknown[]) => acceptMatrixVerificationMock(...args),
6873bootstrapMatrixVerification: (...args: unknown[]) => bootstrapMatrixVerificationMock(...args),
@@ -840,8 +845,9 @@ describe("matrix CLI verification commands", () => {
840845841846await program.parseAsync(["matrix", "verify", "status"], { from: "user" });
842847843-expectRecordFields(mockCallArg(getMatrixVerificationStatusMock), { cfg: fakeCfg });
844-expect(getMatrixVerificationStatusMock.mock.calls.at(-1)?.[0]).not.toHaveProperty("readiness");
848+const statusArg = mockCallArg(getMatrixVerificationStatusMock, -1);
849+expectRecordFields(statusArg, { cfg: fakeCfg });
850+expect(statusArg).not.toHaveProperty("readiness");
845851});
846852847853it("allows verify status to use degraded local-state diagnostics", async () => {
@@ -1206,7 +1212,7 @@ describe("matrix CLI verification commands", () => {
12061212const statusArg = mockCallArg(getMatrixVerificationStatusMock) as Record<string, unknown>;
12071213expectRecordFields(statusArg, { accountId: "ops", readiness: "none" });
12081214expect(statusArg.cfg).toBeTypeOf("object");
1209-const jsonOutput = stdoutWriteMock.mock.calls.at(-1)?.[0];
1215+const jsonOutput = stdoutWriteArg();
12101216expect(typeof jsonOutput).toBe("string");
12111217const payload = JSON.parse(String(jsonOutput)) as Record<string, unknown>;
12121218expectRecordFields(payload, { accountId: "ops", encryptionChanged: false });
@@ -1367,7 +1373,7 @@ describe("matrix CLI verification commands", () => {
1367137313681374expect(matrixRuntimeReplaceConfigFileMock).toHaveBeenCalled();
13691375expect(process.exitCode).toBeUndefined();
1370-const jsonOutput = stdoutWriteMock.mock.calls.at(-1)?.[0];
1376+const jsonOutput = stdoutWriteArg();
13711377expect(typeof jsonOutput).toBe("string");
13721378const payload = JSON.parse(String(jsonOutput)) as Record<string, unknown>;
13731379expect(payload.accountId).toBe("ops");
@@ -1512,7 +1518,7 @@ describe("matrix CLI verification commands", () => {
15121518});
1513151915141520expect(process.exitCode).toBe(1);
1515-expect(JSON.parse(String(stdoutWriteMock.mock.calls.at(0)?.[0]))).toEqual({
1521+expect(JSON.parse(String(stdoutWriteArg(0)))).toEqual({
15161522error: "Matrix requires --homeserver",
15171523});
15181524});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。