From b6370d20a488dd6b2a9838f1b70536deff20d626 Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Mon, 18 Nov 2024 09:54:36 +0100 Subject: [PATCH] Use fetch helper function instead of native otherwise we cannot run the test on v16 supertest acts weird with the custom router, so we need to create a server manually --- library/helpers/fetch.ts | 12 ++++++------ library/sources/Express.test.ts | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/library/helpers/fetch.ts b/library/helpers/fetch.ts index 1c76c9d98..f0b642f7d 100644 --- a/library/helpers/fetch.ts +++ b/library/helpers/fetch.ts @@ -52,16 +52,16 @@ async function request({ export async function fetch({ url, - method, - headers, + method = "GET", + headers = {}, body = "", - timeoutInMS, + timeoutInMS = 5000, }: { url: URL; - method: string; - headers: Record; + method?: string; + headers?: Record; body?: string; - timeoutInMS: number; + timeoutInMS?: number; }): Promise<{ body: string; statusCode: number }> { const abort = new AbortController(); diff --git a/library/sources/Express.test.ts b/library/sources/Express.test.ts index 8f415c11c..d6ffcc122 100644 --- a/library/sources/Express.test.ts +++ b/library/sources/Express.test.ts @@ -5,6 +5,7 @@ import { Express } from "./Express"; import { FileSystem } from "../sinks/FileSystem"; import { HTTPServer } from "./HTTPServer"; import { createTestAgent } from "../helpers/createTestAgent"; +import { fetch } from "../helpers/fetch"; // Before require("express") const agent = createTestAgent({ @@ -639,8 +640,10 @@ t.test( throw new Error("address is a string"); } - const response = await fetch(`http://localhost:${address!.port}/foo`); - t.same(await response.text(), "bar"); + const response = await fetch({ + url: new URL(`http://localhost:${address!.port}/foo`), + }); + t.same(response.body, "bar"); server.close(); if (!routerLayer) {