Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions apps/desktop/src/preview/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,40 @@ describe("PreviewManager", () => {
),
);

effectIt.effect("preserves both screenshots of the same site in the same millisecond", () =>
withManager((manager) =>
Effect.gen(function* () {
const firstPng = Buffer.from("first-preview-png");
const secondPng = Buffer.from("second-preview-png");
const pngImage = (png: Buffer) => ({
toPNG: () => png,
toJPEG: () => png,
getSize: () => ({ width: 1280, height: 720 }),
});
const capturePage = vi
.fn<() => Promise<ReturnType<typeof pngImage>>>()
.mockResolvedValueOnce(pngImage(firstPng))
.mockResolvedValueOnce(pngImage(secondPng));
fromId.mockReturnValue(makeTestPreviewWebContents(capturePage));
yield* manager.createTab("tab_1");
yield* manager.registerWebview("tab_1", 42);
// it.effect keeps TestClock fixed until explicitly advanced.
const first = yield* manager.captureScreenshot("tab_1");
const second = yield* manager.captureScreenshot("tab_1");

expect(first.createdAt).toBe(second.createdAt);
expect(first.id).not.toBe(second.id);
expect(first.path).not.toBe(second.path);
expect(first.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/);
expect(second.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/);
expect(writeFile.mock.calls).toEqual([
[first.path, firstPng],
[second.path, secondPng],
]);
}),
),
);

effectIt.effect("keeps every recorded guest unthrottled until its frame capture stops", () =>
withManager((manager) =>
Effect.gen(function* () {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
wc,
),
]);
const id = `browser-screenshot-${artifactSiteSlug(wc.getURL())}-${millis.toString(36)}`;
const id = `browser-screenshot-${artifactSiteSlug(wc.getURL())}-${millis.toString(36)}-${NodeCrypto.randomUUID().slice(0, 8)}`;
const artifactPath = path.join(resolvedArtifactDirectory, `${id}.png`);
const data = image.toPNG();
yield* fileSystem.makeDirectory(resolvedArtifactDirectory, { recursive: true }).pipe(
Expand Down
Loading