mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 09:16:55 +00:00
fix(studio): an edit the history could not record says why in the log (#5489)
This commit is contained in:
@@ -561,7 +561,9 @@ it("a claim the server refused is logged, and the write stays undoable as a chan
|
||||
files: { "index.html": { before: "A", after: "B" } },
|
||||
}),
|
||||
);
|
||||
expect(logged).toHaveBeenCalledWith('"Moved Title" was not recorded as your edit: disk full');
|
||||
expect(logged).toHaveBeenCalledWith(
|
||||
'[history] 500: "Moved Title" was not recorded as your edit: disk full',
|
||||
);
|
||||
restoreFetch();
|
||||
expect(await act(() => hook().undo({ readFile }))).toMatchObject({
|
||||
ok: true,
|
||||
@@ -570,6 +572,46 @@ it("a claim the server refused is logged, and the write stays undoable as a chan
|
||||
expect(file()).toBe("A");
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"the server refused",
|
||||
409,
|
||||
() => answer("/history/claim", 409, { error: "newer edit" }),
|
||||
"newer edit",
|
||||
],
|
||||
[
|
||||
"could not reach the server",
|
||||
0,
|
||||
() => {
|
||||
const real = globalThis.fetch;
|
||||
vi.stubGlobal("fetch", (url: string, init?: RequestInit) =>
|
||||
url.endsWith("/history/claim")
|
||||
? Promise.reject(new TypeError("fetch failed"))
|
||||
: real(url, init),
|
||||
);
|
||||
},
|
||||
"Studio could not reach its server.",
|
||||
],
|
||||
] as const)(
|
||||
"a claim that %s logs under [history] with its status",
|
||||
async (_, status, stub, reason) => {
|
||||
const { hook, save } = await studio();
|
||||
const logged = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
cleanup.push(() => logged.mockRestore());
|
||||
stub();
|
||||
save("B");
|
||||
await act(() =>
|
||||
hook().recordEdit({
|
||||
label: "Moved Title",
|
||||
files: { "index.html": { before: "A", after: "B" } },
|
||||
}),
|
||||
);
|
||||
expect(logged).toHaveBeenCalledWith(
|
||||
`[history] ${status}: "Moved Title" was not recorded as your edit: ${reason}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("a step whose reply cannot be read says so, instead of throwing", async () => {
|
||||
const { hook, readFile } = await studio();
|
||||
answer("/history/step", 200, "<html>");
|
||||
|
||||
@@ -154,7 +154,9 @@ function claimHeld(reply: Awaited<ReturnType<typeof post>>, label: string): stri
|
||||
if (reply.ok)
|
||||
return (reply.body as { claimed: { id: string } | null } | null)?.claimed?.id ?? null;
|
||||
if (reply.status !== 404)
|
||||
console.error(`"${label}" was not recorded as your edit: ${reply.error}`);
|
||||
console.error(
|
||||
`[history] ${reply.status}: "${label}" was not recorded as your edit: ${reply.error}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user