diff --git a/packages/cactus-common/src/main/typescript/servers.ts b/packages/cactus-common/src/main/typescript/servers.ts index d93cc2853b..88a6b33ba6 100644 --- a/packages/cactus-common/src/main/typescript/servers.ts +++ b/packages/cactus-common/src/main/typescript/servers.ts @@ -43,7 +43,10 @@ export class Servers { Checks.truthy(options, `${fnTag} arg options`); Checks.truthy(options.server, `${fnTag} arg options.server`); - Checks.truthy(options.port, `${fnTag} arg options.port`); + Checks.truthy( + options.port || options.port === 0, + `${fnTag} arg options.port` + ); Checks.truthy(options.hostname, `${fnTag} arg options.hostname`); const { server, port, hostname } = options; diff --git a/packages/cactus-common/src/test/typescript/unit/servers.test.ts b/packages/cactus-common/src/test/typescript/unit/servers.test.ts new file mode 100644 index 0000000000..6ca90802f7 --- /dev/null +++ b/packages/cactus-common/src/test/typescript/unit/servers.test.ts @@ -0,0 +1,41 @@ +import { createServer } from "http"; + +import test, { Test } from "tape-promise/tape"; + +import { Servers } from "../../../main/typescript/index"; + +test("Servers", async (tParent: Test) => { + test("Servers#listen()", async (t: Test) => { + { + const server = createServer(); + await t.rejects( + Servers.listen({ hostname: "x", port: "" as any, server }), + /options\.port/, + "Rejects when port specified as empty string OK" + ); + } + + { + const server = createServer(); + await t.rejects( + Servers.listen({ hostname: "localhost", port: false as any, server }), + /options\.port/, + "Rejects when port specified as literal false boolean OK" + ); + // await Servers.shutdown(server); + } + + { + const server = createServer(); + await t.doesNotReject( + Servers.listen({ hostname: "localhost", port: 0, server }), + "Does not rejects when port specified as zero OK" + ); + await Servers.shutdown(server); + } + + t.end(); + }); + + tParent.end(); +});