























@@ -78,6 +78,29 @@ async function startWatchdogScenario(params: {
7878return { scripted, sleep, spies, ...started };
7979}
808081+function expectErrorContaining(errorFn: unknown, text: string): void {
82+const messages = ((errorFn as { mock?: { calls?: unknown[][] } }).mock?.calls ?? []).map((call) =>
83+typeof call[0] === "string" ? call[0] : call[0] instanceof Error ? call[0].message : "",
84+);
85+expect(messages.some((message) => message.includes(text))).toBe(true);
86+}
87+88+function mockCallArg(mocked: unknown, callIndex: number, argIndex: number): unknown {
89+const calls = (mocked as { mock?: { calls?: unknown[][] } }).mock?.calls;
90+expect(calls?.[callIndex]).toBeDefined();
91+return calls?.[callIndex]?.[argIndex];
92+}
93+94+async function expectPathMissing(targetPath: string): Promise<void> {
95+try {
96+await fs.stat(targetPath);
97+} catch (error) {
98+expect((error as { code?: unknown }).code).toBe("ENOENT");
99+return;
100+}
101+throw new Error(`Expected path to be missing: ${targetPath}`);
102+}
103+81104describe("web auto-reply connection", () => {
82105installWebAutoReplyUnitTestHooks();
83106@@ -140,7 +163,7 @@ describe("web auto-reply connection", () => {
140163await run;
141164}
142165143-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining(scenario.expectedError));
166+expectErrorContaining(runtime.error, scenario.expectedError);
144167}
145168});
146169@@ -186,9 +209,9 @@ describe("web auto-reply connection", () => {
186209expect(completedQuickly).toBe(true);
187210expect(scripted.getListenerCount()).toBe(1);
188211expect(sleep).not.toHaveBeenCalled();
189-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("status 440"));
190-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("session conflict"));
191-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("Stopping web monitoring"));
212+expectErrorContaining(runtime.error, "status 440");
213+expectErrorContaining(runtime.error, "session conflict");
214+expectErrorContaining(runtime.error, "Stopping web monitoring");
192215});
193216194217it.each([
@@ -260,20 +283,14 @@ describe("web auto-reply connection", () => {
260283expect(scripted.getListenerCount()).toBe(1);
261284expect(sleep).not.toHaveBeenCalled();
262285expect(getActiveWebListener(accountId)).toBeNull();
263-await expect(fs.stat(authDir)).rejects.toMatchObject({ code: "ENOENT" });
264-expect(statuses).toContainEqual(
265-expect.objectContaining({
266-connected: false,
267- healthState,
268-}),
269-);
270-expect(statuses.at(-1)).toEqual(
271-expect.objectContaining({
272-running: false,
273-connected: false,
274- healthState,
275-}),
276-);
286+await expectPathMissing(authDir);
287+expect(
288+statuses.some((entry) => entry.connected === false && entry.healthState === healthState),
289+).toBe(true);
290+const finalStatus = statuses.at(-1);
291+expect(finalStatus?.running).toBe(false);
292+expect(finalStatus?.connected).toBe(false);
293+expect(finalStatus?.healthState).toBe(healthState);
277294},
278295);
279296@@ -304,8 +321,9 @@ describe("web auto-reply connection", () => {
304321controller.abort();
305322await run;
306323307-expect(sleep).toHaveBeenCalledWith(expect.any(Number), expect.any(AbortSignal));
308-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("inbox attach"));
324+expect(typeof mockCallArg(sleep, 0, 0)).toBe("number");
325+expect(mockCallArg(sleep, 0, 1)).toBeInstanceOf(AbortSignal);
326+expectErrorContaining(runtime.error, "inbox attach");
309327});
310328311329it("stops retrying inbox attach when auth stays unstable past max attempts", async () => {
@@ -326,8 +344,8 @@ describe("web auto-reply connection", () => {
326344327345expect(listenerFactory).toHaveBeenCalledTimes(2);
328346expect(sleep).toHaveBeenCalledTimes(1);
329-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("Retry 1/2"));
330-expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("Stopping web monitoring"));
347+expectErrorContaining(runtime.error, "Retry 1/2");
348+expectErrorContaining(runtime.error, "Stopping web monitoring");
331349});
332350333351it("forces reconnect when watchdog closes without onClose", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。