export async function downloadAsZip(): Promise<void> {
if (captured.size === 0) {
console.warn("[ResponseAggregate] No responses captured yet.");
return;
}
const zip = new JSZip();
for (const [filePath, entry] of captured) {
// Include request metadata alongside the MSW-compatible fields so
// the e2e mock route handler can match by URL without recomputing hashes.
const fileContent = JSON.stringify(
{
contentType: entry.contentType,
content: entry.content,
_request: {
url: entry.url,
method: entry.method,
},
},
null,
2,
);
zip.file(filePath, fileContent);
}
const blob = await zip.generateAsync({ type: "blob" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `response-aggregate-${new Date().toISOString().slice(0, 19).replace(/:/g, "-")}.zip`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
console.log(`[ResponseAggregate] Downloaded zip with ${captured.size} responses.`);
}
Download all captured responses as a zip file. The zip structure mirrors
src/__mocks__/responses/{hostname}/{hash}.json.