| ... | ... | @@ -2367,6 +2367,40 @@ describe("PreviewManager", () => { |
| 2367 | 2367 | ), |
| 2368 | 2368 | ); |
| 2369 | 2369 | |
| 2370 | effectIt.effect("preserves both screenshots of the same site in the same millisecond", () => |
| 2371 | withManager((manager) => |
| 2372 | Effect.gen(function* () { |
| 2373 | const firstPng = Buffer.from("first-preview-png"); |
| 2374 | const secondPng = Buffer.from("second-preview-png"); |
| 2375 | const pngImage = (png: Buffer) => ({ |
| 2376 | toPNG: () => png, |
| 2377 | toJPEG: () => png, |
| 2378 | getSize: () => ({ width: 1280, height: 720 }), |
| 2379 | }); |
| 2380 | const capturePage = vi |
| 2381 | .fn<() => Promise<ReturnType<typeof pngImage>>>() |
| 2382 | .mockResolvedValueOnce(pngImage(firstPng)) |
| 2383 | .mockResolvedValueOnce(pngImage(secondPng)); |
| 2384 | fromId.mockReturnValue(makeTestPreviewWebContents(capturePage)); |
| 2385 | yield* manager.createTab("tab_1"); |
| 2386 | yield* manager.registerWebview("tab_1", 42); |
| 2387 | // it.effect keeps TestClock fixed until explicitly advanced. |
| 2388 | const first = yield* manager.captureScreenshot("tab_1"); |
| 2389 | const second = yield* manager.captureScreenshot("tab_1"); |
| 2390 | |
| 2391 | expect(first.createdAt).toBe(second.createdAt); |
| 2392 | expect(first.id).not.toBe(second.id); |
| 2393 | expect(first.path).not.toBe(second.path); |
| 2394 | expect(first.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/); |
| 2395 | expect(second.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/); |
| 2396 | expect(writeFile.mock.calls).toEqual([ |
| 2397 | [first.path, firstPng], |
| 2398 | [second.path, secondPng], |
| 2399 | ]); |
| 2400 | }), |
| 2401 | ), |
| 2402 | ); |
| 2403 | |
| 2370 | 2404 | effectIt.effect("keeps every recorded guest unthrottled until its frame capture stops", () => |
| 2371 | 2405 | withManager((manager) => |
| 2372 | 2406 | Effect.gen(function* () { |