Skip to content

Commit

Permalink
fix: pass port options object to getPort (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkswrnr committed Nov 28, 2022
1 parent 6a93201 commit 8cc07e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export async function listen (handle: RequestListener, options_: Partial<ListenO
const port = await getPort({
port: Number(options_.port),
verbose: !options_.isTest,
host: options_.hostname
host: options_.hostname,
...(typeof options_.port === "object" && options_.port)
});

let server: Server | HTTPServer;
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,19 @@ describe("listhen", () => {
// @ts-ignore
process.emit("exit");
});

test("pass hostname to get-port-please", async () => {
listener = await listen(handle, { hostname: "127.0.0.1" });
expect(listener.url.startsWith("http://127.0.0.1")).toBe(true);
});

test("pass port to get-port-please", async () => {
listener = await listen(handle, { port: 40_000 });
expect(listener.url.endsWith(":40000/")).toBe(true);
});

test("pass extended options to get-port-please", async () => {
listener = await listen(handle, { port: { portRange: [50_000, 59_999] } });
expect(listener.url).toMatch(/:5\d{4}\/$/);
});
});

0 comments on commit 8cc07e0

Please sign in to comment.