| 616 | |
| 617 | describe("cache replay", () => { |
| 618 | async function makeRequest( |
| 619 | proxyUrl: string, |
| 620 | requestPath: string, |
| 621 | options?: { method?: string; body?: object }, |
| 622 | ): Promise<{ status: number; body: string }> { |
| 623 | return new Promise((resolve, reject) => { |
| 624 | const url = new URL(proxyUrl); |
| 625 | const req = http.request( |
| 626 | { |
| 627 | hostname: url.hostname, |
| 628 | port: url.port, |
| 629 | path: requestPath, |
| 630 | method: options?.method ?? "POST", |
| 631 | headers: { "content-type": "application/json" }, |
| 632 | }, |
| 633 | (res) => { |
| 634 | const chunks: Buffer[] = []; |
| 635 | res.on("data", (chunk: Buffer) => chunks.push(chunk)); |
| 636 | res.on("end", () => { |
| 637 | resolve({ |
| 638 | status: res.statusCode || 500, |
| 639 | body: Buffer.concat(chunks).toString("utf-8"), |
| 640 | }); |
| 641 | }); |
| 642 | }, |
| 643 | ); |
| 644 | req.on("error", reject); |
| 645 | if (options?.body) { |
| 646 | req.write(JSON.stringify(options.body)); |
| 647 | } |
| 648 | req.end(); |
| 649 | }); |
| 650 | } |
| 651 | |
| 652 | test("returns cached response when request matches prefix", async () => { |
| 653 | const cachePath = path.join(tempDir, "cache.yaml"); |