Skip to content

Commit

Permalink
Use fetch helper function instead of native
Browse files Browse the repository at this point in the history
otherwise we cannot run the test on v16

supertest acts weird with the custom router, so we need to create a server manually
  • Loading branch information
hansott committed Nov 18, 2024
1 parent 26667fa commit b6370d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions library/helpers/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
method?: string;
headers?: Record<string, string>;
body?: string;
timeoutInMS: number;
timeoutInMS?: number;
}): Promise<{ body: string; statusCode: number }> {
const abort = new AbortController();

Expand Down
7 changes: 5 additions & 2 deletions library/sources/Express.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b6370d2

Please sign in to comment.