Skip to content

Commit

Permalink
fix: add default port range (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Mar 13, 2023
1 parent 767c9ed commit 9481c97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export async function listen(
port: Number(options_.port),
verbose: !options_.isTest,
host: options_.hostname,
alternativePortRange: [3000, 3100],
...(typeof options_.port === "object" && options_.port),
});

Expand Down
12 changes: 12 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,16 @@ describe("listhen", () => {
});
expect(listener.url).toMatch(/:5\d{4}\/$/);
});

test("should listen to the next port in range (3000 -> 31000)", async () => {
listener = await listen(handle, {
port: { port: 3000 },
});
expect(listener.url).toMatch(/:3000\/$/);
const listener2 = await listen(handle, {
port: { port: 3000 },
});
expect(listener2.url).toMatch(/:3001\/$/);
await listener2.close();
});
});

0 comments on commit 9481c97

Please sign in to comment.