mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 12:04:47 +00:00
test: tighten diffs tool assertions
This commit is contained in:
@@ -38,8 +38,8 @@ describe("diffs tool", () => {
|
||||
|
||||
const text = readTextContent(result, 0);
|
||||
expect(text).toContain("http://127.0.0.1:18789/plugins/diffs/view/");
|
||||
expect(readDetails(result).viewerUrl).toEqual(
|
||||
expect.stringContaining("http://127.0.0.1:18789/plugins/diffs/view/"),
|
||||
expect(String(readDetails(result).viewerUrl)).toContain(
|
||||
"http://127.0.0.1:18789/plugins/diffs/view/",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -63,8 +63,8 @@ describe("diffs tool", () => {
|
||||
expect(readTextContent(result, 0)).toContain(
|
||||
"https://example.com/openclaw/plugins/diffs/view/",
|
||||
);
|
||||
expect((result?.details as Record<string, unknown>).viewerUrl).toEqual(
|
||||
expect.stringContaining("https://example.com/openclaw/plugins/diffs/view/"),
|
||||
expect(String((result?.details as Record<string, unknown>).viewerUrl)).toContain(
|
||||
"https://example.com/openclaw/plugins/diffs/view/",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -89,8 +89,8 @@ describe("diffs tool", () => {
|
||||
expect(readTextContent(result, 0)).toContain(
|
||||
"https://preview.example.com/review/plugins/diffs/view/",
|
||||
);
|
||||
expect((result?.details as Record<string, unknown>).viewerUrl).toEqual(
|
||||
expect.stringContaining("https://preview.example.com/review/plugins/diffs/view/"),
|
||||
expect(String((result?.details as Record<string, unknown>).viewerUrl)).toContain(
|
||||
"https://preview.example.com/review/plugins/diffs/view/",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -112,12 +112,10 @@ describe("diffs tool", () => {
|
||||
expect(html).toContain("../../assets/viewer.js");
|
||||
},
|
||||
assertImage: (image) => {
|
||||
expect(image).toMatchObject({
|
||||
format: "png",
|
||||
qualityPreset: "standard",
|
||||
scale: 2,
|
||||
maxWidth: 960,
|
||||
});
|
||||
expect(image.format).toBe("png");
|
||||
expect(image.qualityPreset).toBe("standard");
|
||||
expect(image.scale).toBe(2);
|
||||
expect(image.maxWidth).toBe(960);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -215,9 +213,7 @@ describe("diffs tool", () => {
|
||||
|
||||
vi.setSystemTime(new Date(now.getTime() + 2_000));
|
||||
await store.cleanupExpired();
|
||||
await expect(fs.stat(filePath)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectFsEnoent(fs.stat(filePath));
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
@@ -244,9 +240,7 @@ describe("diffs tool", () => {
|
||||
|
||||
vi.setSystemTime(new Date(now.getTime() + 61_000));
|
||||
await store.cleanupExpired();
|
||||
await expect(fs.stat(filePath)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectFsEnoent(fs.stat(filePath));
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
@@ -255,11 +249,9 @@ describe("diffs tool", () => {
|
||||
it("accepts image* tool options for backward compatibility", async () => {
|
||||
const screenshotter = createPngScreenshotter({
|
||||
assertImage: (image) => {
|
||||
expect(image).toMatchObject({
|
||||
qualityPreset: "hq",
|
||||
scale: 2.4,
|
||||
maxWidth: 1100,
|
||||
});
|
||||
expect(image.qualityPreset).toBe("hq");
|
||||
expect(image.scale).toBe(2.4);
|
||||
expect(image.maxWidth).toBe(1100);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -439,12 +431,10 @@ describe("diffs tool", () => {
|
||||
expect(html).toContain("../../assets/viewer.js");
|
||||
},
|
||||
assertImage: (image) => {
|
||||
expect(image).toMatchObject({
|
||||
format: "png",
|
||||
qualityPreset: "print",
|
||||
scale: 2.75,
|
||||
maxWidth: 1320,
|
||||
});
|
||||
expect(image.format).toBe("png");
|
||||
expect(image.qualityPreset).toBe("print");
|
||||
expect(image.scale).toBe(2.75);
|
||||
expect(image.maxWidth).toBe(1320);
|
||||
},
|
||||
});
|
||||
const tool = createToolWithScreenshotter(store, screenshotter, {
|
||||
@@ -639,6 +629,16 @@ function requireString(value: unknown, label: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
async function expectFsEnoent(promise: Promise<unknown>): Promise<void> {
|
||||
try {
|
||||
await promise;
|
||||
} catch (error) {
|
||||
expect((error as { code?: unknown }).code).toBe("ENOENT");
|
||||
return;
|
||||
}
|
||||
throw new Error("expected ENOENT");
|
||||
}
|
||||
|
||||
function readTextContent(result: unknown, index: number): string {
|
||||
const content = (result as { content?: Array<{ type?: string; text?: string }> } | undefined)
|
||||
?.content;
|
||||
|
||||
Reference in New Issue
Block a user