Skip to content

Commit 47a86a7

Browse files
committed
fix(desktop): give every browser screenshot a unique artifact name
1 parent 54084ae commit 47a86a7

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,46 @@ describe("PreviewManager", () => {
22402240
),
22412241
);
22422242

2243+
effectIt.effect("preserves both screenshots of the same site in the same millisecond", () =>
2244+
withManager((manager) =>
2245+
Effect.gen(function* () {
2246+
const firstPng = Buffer.from("first-preview-png");
2247+
const secondPng = Buffer.from("second-preview-png");
2248+
const capturePage = vi.fn(async () => ({
2249+
toPNG: () => firstPng,
2250+
toJPEG: () => firstPng,
2251+
getSize: () => ({ width: 1280, height: 720 }),
2252+
}));
2253+
capturePage.mockResolvedValueOnce({
2254+
toPNG: () => firstPng,
2255+
toJPEG: () => firstPng,
2256+
getSize: () => ({ width: 1280, height: 720 }),
2257+
});
2258+
capturePage.mockResolvedValueOnce({
2259+
toPNG: () => secondPng,
2260+
toJPEG: () => secondPng,
2261+
getSize: () => ({ width: 1280, height: 720 }),
2262+
});
2263+
fromId.mockReturnValue(makeTestPreviewWebContents(capturePage));
2264+
yield* manager.createTab("tab_1");
2265+
yield* manager.registerWebview("tab_1", 42);
2266+
// it.effect keeps TestClock fixed until explicitly advanced.
2267+
const first = yield* manager.captureScreenshot("tab_1");
2268+
const second = yield* manager.captureScreenshot("tab_1");
2269+
2270+
expect(first.createdAt).toBe(second.createdAt);
2271+
expect(first.id).not.toBe(second.id);
2272+
expect(first.path).not.toBe(second.path);
2273+
expect(first.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/);
2274+
expect(second.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/);
2275+
expect(writeFile.mock.calls).toEqual([
2276+
[first.path, firstPng],
2277+
[second.path, secondPng],
2278+
]);
2279+
}),
2280+
),
2281+
);
2282+
22432283
effectIt.effect("keeps every recorded guest unthrottled until its frame capture stops", () =>
22442284
withManager((manager) =>
22452285
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2884,7 +2884,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
28842884
wc,
28852885
),
28862886
]);
2887-
const id = `browser-screenshot-${artifactSiteSlug(wc.getURL())}-${millis.toString(36)}`;
2887+
const id = `browser-screenshot-${artifactSiteSlug(wc.getURL())}-${millis.toString(36)}-${NodeCrypto.randomUUID().slice(0, 8)}`;
28882888
const artifactPath = path.join(resolvedArtifactDirectory, `${id}.png`);
28892889
const data = image.toPNG();
28902890
yield* fileSystem.makeDirectory(resolvedArtifactDirectory, { recursive: true }).pipe(

0 commit comments

Comments
 (0)