

























@@ -38,8 +38,8 @@ describe("diffs tool", () => {
38383939const text = readTextContent(result, 0);
4040expect(text).toContain("http://127.0.0.1:18789/plugins/diffs/view/");
41-expect(readDetails(result).viewerUrl).toEqual(
42-expect.stringContaining("http://127.0.0.1:18789/plugins/diffs/view/"),
41+expect(String(readDetails(result).viewerUrl)).toContain(
42+"http://127.0.0.1:18789/plugins/diffs/view/",
4343);
4444});
4545@@ -63,8 +63,8 @@ describe("diffs tool", () => {
6363expect(readTextContent(result, 0)).toContain(
6464"https://example.com/openclaw/plugins/diffs/view/",
6565);
66-expect((result?.details as Record<string, unknown>).viewerUrl).toEqual(
67-expect.stringContaining("https://example.com/openclaw/plugins/diffs/view/"),
66+expect(String((result?.details as Record<string, unknown>).viewerUrl)).toContain(
67+"https://example.com/openclaw/plugins/diffs/view/",
6868);
6969});
7070@@ -89,8 +89,8 @@ describe("diffs tool", () => {
8989expect(readTextContent(result, 0)).toContain(
9090"https://preview.example.com/review/plugins/diffs/view/",
9191);
92-expect((result?.details as Record<string, unknown>).viewerUrl).toEqual(
93-expect.stringContaining("https://preview.example.com/review/plugins/diffs/view/"),
92+expect(String((result?.details as Record<string, unknown>).viewerUrl)).toContain(
93+"https://preview.example.com/review/plugins/diffs/view/",
9494);
9595});
9696@@ -112,12 +112,10 @@ describe("diffs tool", () => {
112112expect(html).toContain("../../assets/viewer.js");
113113},
114114assertImage: (image) => {
115-expect(image).toMatchObject({
116-format: "png",
117-qualityPreset: "standard",
118-scale: 2,
119-maxWidth: 960,
120-});
115+expect(image.format).toBe("png");
116+expect(image.qualityPreset).toBe("standard");
117+expect(image.scale).toBe(2);
118+expect(image.maxWidth).toBe(960);
121119},
122120});
123121@@ -215,9 +213,7 @@ describe("diffs tool", () => {
215213216214vi.setSystemTime(new Date(now.getTime() + 2_000));
217215await store.cleanupExpired();
218-await expect(fs.stat(filePath)).rejects.toMatchObject({
219-code: "ENOENT",
220-});
216+await expectFsEnoent(fs.stat(filePath));
221217} finally {
222218vi.useRealTimers();
223219}
@@ -244,9 +240,7 @@ describe("diffs tool", () => {
244240245241vi.setSystemTime(new Date(now.getTime() + 61_000));
246242await store.cleanupExpired();
247-await expect(fs.stat(filePath)).rejects.toMatchObject({
248-code: "ENOENT",
249-});
243+await expectFsEnoent(fs.stat(filePath));
250244} finally {
251245vi.useRealTimers();
252246}
@@ -255,11 +249,9 @@ describe("diffs tool", () => {
255249it("accepts image* tool options for backward compatibility", async () => {
256250const screenshotter = createPngScreenshotter({
257251assertImage: (image) => {
258-expect(image).toMatchObject({
259-qualityPreset: "hq",
260-scale: 2.4,
261-maxWidth: 1100,
262-});
252+expect(image.qualityPreset).toBe("hq");
253+expect(image.scale).toBe(2.4);
254+expect(image.maxWidth).toBe(1100);
263255},
264256});
265257@@ -439,12 +431,10 @@ describe("diffs tool", () => {
439431expect(html).toContain("../../assets/viewer.js");
440432},
441433assertImage: (image) => {
442-expect(image).toMatchObject({
443-format: "png",
444-qualityPreset: "print",
445-scale: 2.75,
446-maxWidth: 1320,
447-});
434+expect(image.format).toBe("png");
435+expect(image.qualityPreset).toBe("print");
436+expect(image.scale).toBe(2.75);
437+expect(image.maxWidth).toBe(1320);
448438},
449439});
450440const tool = createToolWithScreenshotter(store, screenshotter, {
@@ -639,6 +629,16 @@ function requireString(value: unknown, label: string): string {
639629return value;
640630}
641631632+async function expectFsEnoent(promise: Promise<unknown>): Promise<void> {
633+try {
634+await promise;
635+} catch (error) {
636+expect((error as { code?: unknown }).code).toBe("ENOENT");
637+return;
638+}
639+throw new Error("expected ENOENT");
640+}
641+642642function readTextContent(result: unknown, index: number): string {
643643const content = (result as { content?: Array<{ type?: string; text?: string }> } | undefined)
644644?.content;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。