Skip to content

Commit

Permalink
chore: Update TCPServer unit test for port in use error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed May 30, 2024
1 parent 27a68b0 commit 3f874e4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/connections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it, vi } from "vitest";
import { TCPServer } from "../src/index.js";

describe("TCPServer", () => {
it("should return an error if the port is in use", () => /** @type {Promise<void>} */(new Promise(done => {
it("should return an error if the port is priviliged", () => /** @type {Promise<void>} */(new Promise(done => {
const onListening = vi.fn();
const onConnection = vi.fn();
const onServerError = vi.fn().mockImplementation((err) => {
Expand All @@ -16,4 +16,18 @@ describe("TCPServer", () => {
const s = new TCPServer(80, onListening, onConnection, onServerError);
s.listen();
})));

it("should return an error if the port is in use", () => /** @type {Promise<void>} */(new Promise(done => {
const onListening = vi.fn();
const onConnection = vi.fn();
const onServerError = vi.fn().mockImplementation((err) => {
expect(err.message).toMatch(/EADDRINUSE/);
done();
});

console.error = vi.fn();

const s = new TCPServer(8080, onListening, onConnection, onServerError);
s.listen();
})));
});

0 comments on commit 3f874e4

Please sign in to comment.