diff --git a/tests/browser-capabilities/browser-files.spec.ts b/tests/browser-capabilities/browser-files.spec.ts index 14c2678..aa7ceb0 100644 --- a/tests/browser-capabilities/browser-files.spec.ts +++ b/tests/browser-capabilities/browser-files.spec.ts @@ -272,7 +272,9 @@ test("hands a bounded generated Blob to the real browser download path", async ( }); const state = globalThis as typeof globalThis & { __browserDownloadResult?: Promise; + __browserDownloadRuntime?: { dispose(): void }; }; + state.__browserDownloadRuntime = runtime; button.addEventListener("click", () => { state.__browserDownloadResult = runtime.downloads .deliver({ @@ -298,8 +300,7 @@ test("hands a bounded generated Blob to the real browser download path", async ( maxBufferedBytes: 1024, signal: new AbortController().signal, onProgress() {}, - }) - .finally(() => runtime.dispose()); + }); }); }); @@ -313,11 +314,19 @@ test("hands a bounded generated Blob to the real browser download path", async ( for await (const chunk of stream) { chunks.push(Buffer.from(chunk)); } + // dispose() revokes every live object URL at once. It used to run as soon + // as deliver() handed the URL to the anchor; WebKit starts the download + // after that, so it sometimes met a revoked URL and never started (no + // "download" event within the test timeout). The runtime is disposed once + // the browser has the file. const result = await page.evaluate(async () => { const state = globalThis as typeof globalThis & { __browserDownloadResult?: Promise; + __browserDownloadRuntime?: { dispose(): void }; }; - return await state.__browserDownloadResult; + const delivered = await state.__browserDownloadResult; + state.__browserDownloadRuntime?.dispose(); + return delivered; }); expect(download.suggestedFilename()).toBe("report.bin");