1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/port_spec.ts
Panu Horsmalahti 460dfe4d2b Use @typescript-eslint/semi.
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
2020-11-19 18:12:52 +02:00

32 lines
701 B
TypeScript

import { EventEmitter } from 'events';
import { getFreePort } from "./port";
let newPort = 0;
jest.mock("net", () => {
return {
createServer() {
return new class MockServer extends EventEmitter {
listen = jest.fn(() => {
this.emit('listening');
return this;
});
address = () => {
newPort = Math.round(Math.random() * 10000);
return {
port: newPort
};
};
unref = jest.fn();
close = jest.fn(cb => cb());
};
},
};
});
describe("getFreePort", () => {
it("finds the next free port", async () => {
return expect(getFreePort()).resolves.toEqual(newPort);
});
});