Skip to content

Commit 9dccfd9

Browse files
committed
test: simplify
1 parent 70c5ac2 commit 9dccfd9

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

test/index.test.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { blockPort } from "./utils";
55

66
const isWindows = process.platform === "win32";
77

8-
describe("getPort ()", () => {
9-
describe("checks ports on default host`", () => {
10-
let portBlocker: Server;
8+
describe("getPort", () => {
9+
let portBlocker: Server;
1110

12-
afterEach(() => {
13-
portBlocker?.close();
14-
});
11+
afterEach(() => {
12+
portBlocker?.close();
13+
});
1514

16-
test("default port is NOT IN USE", async () => {
15+
describe("default host`", () => {
16+
test("default port is not in use", async () => {
1717
const port = await getPort();
1818
expect(port).toEqual(3000);
1919
});
@@ -24,48 +24,26 @@ describe("getPort ()", () => {
2424
expect(port).toEqual(3001);
2525
});
2626
});
27-
});
2827

29-
describe("getPort (host)", () => {
30-
describe("checks ports on `localhost`", () => {
31-
let portBlocker: Server;
32-
33-
afterEach(() => {
34-
portBlocker?.close();
35-
});
36-
37-
test("default port is NOT IN USE", async () => {
28+
describe("localhost", () => {
29+
test("default port is not in use", async () => {
3830
const port = await getPort({ host: "localhost" });
3931
expect(port).toEqual(3000);
4032
});
4133

42-
test("default port is IN USE", async () => {
34+
test("default port is in use", async () => {
35+
process.env.HOST = "localhost";
4336
portBlocker = await blockPort(3000, "localhost");
44-
const port = await getPort({ host: "localhost" });
45-
expect(port).toEqual(3001);
37+
const port1 = await getPort({ port: 3000, portRange: [3000, 3100] });
38+
expect(port1).toEqual(3001);
39+
const port2 = await getPort();
40+
expect(port2).toEqual(3001);
41+
const port3 = await getPort(3000);
42+
expect(port3).not.toEqual(3001);
4643
});
4744
});
4845
});
4946

50-
describe("getPort (host)", () => {
51-
let portBlocker: Server;
52-
53-
afterEach(() => {
54-
portBlocker?.close();
55-
});
56-
57-
test("default port is in use", async () => {
58-
process.env.HOST = "localhost";
59-
portBlocker = await blockPort(3000, "localhost");
60-
const port1 = await getPort({ port: 3000, portRange: [3000, 3100] });
61-
expect(port1).toEqual(3001);
62-
const port2 = await getPort();
63-
expect(port2).toEqual(3001);
64-
const port3 = await getPort(3000);
65-
expect(port3).not.toEqual(3001);
66-
});
67-
});
68-
6947
describe("random port", () => {
7048
test("{ random: true }", async () => {
7149
const port = await getPort({ random: true });

0 commit comments

Comments
 (0)