|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { parsePort } from "./parse-port.js"; |
3 | 3 | |
4 | | -describe("parsePort (#83900)", () => { |
| 4 | +describe("parsePort (#83899, #83900)", () => { |
5 | 5 | it("returns null for nullish inputs", () => { |
6 | 6 | expect(parsePort(undefined)).toBeNull(); |
7 | 7 | expect(parsePort(null)).toBeNull(); |
8 | 8 | }); |
9 | 9 | |
10 | | -it("returns null for zero and negative values (already enforced)", () => { |
| 10 | +it("returns null for zero and negative values", () => { |
11 | 11 | expect(parsePort(0)).toBeNull(); |
12 | 12 | expect(parsePort(-1)).toBeNull(); |
13 | 13 | expect(parsePort("0")).toBeNull(); |
@@ -16,22 +16,26 @@ describe("parsePort (#83900)", () => {
|
16 | 16 | it("accepts valid TCP port values", () => { |
17 | 17 | expect(parsePort(1)).toBe(1); |
18 | 18 | expect(parsePort(8080)).toBe(8080); |
| 19 | +expect(parsePort("8080")).toBe(8080); |
19 | 20 | expect(parsePort("3000")).toBe(3000); |
20 | | -expect(parsePort(65535)).toBe(65535); |
| 21 | +expect(parsePort(" 65535 ")).toBe(65_535); |
21 | 22 | }); |
22 | 23 | |
23 | | -it("rejects port numbers above 65535 (regression for #83900)", () => { |
24 | | -expect(parsePort(65536)).toBeNull(); |
| 24 | +it("rejects port numbers above 65535", () => { |
| 25 | +expect(parsePort(65_536)).toBeNull(); |
25 | 26 | expect(parsePort(99999)).toBeNull(); |
26 | 27 | expect(parsePort("100000")).toBeNull(); |
| 28 | +expect(parsePort(Number.MAX_SAFE_INTEGER + 1)).toBeNull(); |
27 | 29 | // Largest 16-bit value is the inclusive boundary. |
28 | | -expect(parsePort(65535)).toBe(65535); |
| 30 | +expect(parsePort(65_535)).toBe(65_535); |
29 | 31 | }); |
30 | 32 | |
31 | 33 | it("rejects non-integer and non-finite inputs", () => { |
32 | 34 | expect(parsePort(1.5)).toBeNull(); |
| 35 | +expect(parsePort("1.5")).toBeNull(); |
33 | 36 | expect(parsePort(Number.NaN)).toBeNull(); |
34 | 37 | expect(parsePort(Number.POSITIVE_INFINITY)).toBeNull(); |
35 | 38 | expect(parsePort("abc")).toBeNull(); |
| 39 | +expect(parsePort("8080ms")).toBeNull(); |
36 | 40 | }); |
37 | 41 | }); |