Skip to content

Commit

Permalink
test: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 7, 2023
1 parent 70c5ac2 commit 9dccfd9
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions test/index.test.ts
Expand Up @@ -5,15 +5,15 @@ import { blockPort } from "./utils";

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

describe("getPort ()", () => {
describe("checks ports on default host`", () => {
let portBlocker: Server;
describe("getPort", () => {
let portBlocker: Server;

afterEach(() => {
portBlocker?.close();
});
afterEach(() => {
portBlocker?.close();
});

test("default port is NOT IN USE", async () => {
describe("default host`", () => {
test("default port is not in use", async () => {
const port = await getPort();
expect(port).toEqual(3000);
});
Expand All @@ -24,48 +24,26 @@ describe("getPort ()", () => {
expect(port).toEqual(3001);
});
});
});

describe("getPort (host)", () => {
describe("checks ports on `localhost`", () => {
let portBlocker: Server;

afterEach(() => {
portBlocker?.close();
});

test("default port is NOT IN USE", async () => {
describe("localhost", () => {
test("default port is not in use", async () => {
const port = await getPort({ host: "localhost" });
expect(port).toEqual(3000);
});

test("default port is IN USE", async () => {
test("default port is in use", async () => {
process.env.HOST = "localhost";
portBlocker = await blockPort(3000, "localhost");
const port = await getPort({ host: "localhost" });
expect(port).toEqual(3001);
const port1 = await getPort({ port: 3000, portRange: [3000, 3100] });
expect(port1).toEqual(3001);
const port2 = await getPort();
expect(port2).toEqual(3001);
const port3 = await getPort(3000);
expect(port3).not.toEqual(3001);
});
});
});

describe("getPort (host)", () => {
let portBlocker: Server;

afterEach(() => {
portBlocker?.close();
});

test("default port is in use", async () => {
process.env.HOST = "localhost";
portBlocker = await blockPort(3000, "localhost");
const port1 = await getPort({ port: 3000, portRange: [3000, 3100] });
expect(port1).toEqual(3001);
const port2 = await getPort();
expect(port2).toEqual(3001);
const port3 = await getPort(3000);
expect(port3).not.toEqual(3001);
});
});

describe("random port", () => {
test("{ random: true }", async () => {
const port = await getPort({ random: true });
Expand Down

0 comments on commit 9dccfd9

Please sign in to comment.