Files
hyperframes/test-utils/renderCancellation.ts
SophiaHuangCc 2d695a8436 feat(studio): support GIF export with loop count (#5593)
* feat(studio): support GIF export with loop count

* fix(studio): cap GIF exports at 30 fps

* fix(studio): complete GIF export review follow-ups
2026-10-26 14:57:55 +00:00

31 lines
864 B
TypeScript

import { existsSync } from "node:fs";
import { expect, vi } from "vitest";
export function waitForRenderCancellation(
signal: AbortSignal,
lateCompletion: boolean,
): Promise<void> {
return new Promise((resolve, reject) => {
signal.addEventListener(
"abort",
() => {
if (lateCompletion) resolve();
else reject(Object.assign(new Error("cancelled"), { name: "AbortError" }));
},
{ once: true },
);
});
}
export async function cancelAndVerifyArtifacts(
state: { status: string; cancel?: () => void },
outputPath: string,
metaPath: string,
): Promise<void> {
await vi.waitFor(() => expect(existsSync(metaPath)).toBe(true));
state.cancel?.();
await vi.waitFor(() => expect(state.status).toBe("cancelled"));
expect(existsSync(outputPath)).toBe(false);
expect(existsSync(metaPath)).toBe(false);
}