轮询 SW 的 chrome.downloads,拿到刚导出的 blob 备份文件在磁盘上的路径
(context: BrowserContext, timeoutMs = 15_000)
| 32 | |
| 33 | /** 轮询 SW 的 chrome.downloads,拿到刚导出的 blob 备份文件在磁盘上的路径 */ |
| 34 | async function waitForExportedZipPath(context: BrowserContext, timeoutMs = 15_000): Promise<string> { |
| 35 | const sw = context.serviceWorkers()[0]; |
| 36 | let filename: string | null = null; |
| 37 | await expect |
| 38 | .poll( |
| 39 | async () => { |
| 40 | filename = await sw.evaluate( |
| 41 | () => |
| 42 | new Promise((resolve) => { |
| 43 | chrome.downloads.search({ limit: 5, orderBy: ["-startTime"] }, (items) => { |
| 44 | const hit = items.find( |
| 45 | (i) => (i.url || "").startsWith("blob:chrome-extension") && i.state === "complete" |
| 46 | ); |
| 47 | resolve(hit ? hit.filename : null); |
| 48 | }); |
| 49 | }) |
| 50 | ); |
| 51 | return filename && fs.existsSync(filename) ? filename : null; |
| 52 | }, |
| 53 | { timeout: timeoutMs, intervals: [100, 250, 500, 1_000] } |
| 54 | ) |
| 55 | .not.toBeNull(); |
| 56 | return filename!; |
| 57 | } |
| 58 | |
| 59 | test.describe("Backup zip export/import round-trip (#1479)", () => { |
| 60 | test("导出备份生成合法 zip,再导入能被 loadAsyncJSZip 解析并列出脚本", async ({ context, extensionId }) => { |
no test coverage detected