Skip to content

Commit f857723

Browse files
committed
feat(testing): add test for app > listen
1 parent 03e0bda commit f857723

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/node/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface App extends Disposable {
2222
server: http.Server
2323
}
2424

25-
const listen = (server: http.Server, { host, port, socket, "socket-mode": mode }: ListenOptions) => {
25+
export const listen = (server: http.Server, { host, port, socket, "socket-mode": mode }: ListenOptions) => {
2626
return new Promise<void>(async (resolve, reject) => {
2727
server.on("error", reject)
2828

test/unit/node/app.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { promises } from "fs"
33
import * as http from "http"
44
import * as https from "https"
55
import * as path from "path"
6-
import { createApp, ensureAddress, handleArgsSocketCatchError, handleServerError } from "../../../src/node/app"
6+
import { createApp, ensureAddress, handleArgsSocketCatchError, handleServerError, listen } from "../../../src/node/app"
77
import { OptionalString, setDefaults } from "../../../src/node/cli"
88
import { generateCertificate } from "../../../src/node/util"
99
import { clean, mockLogger, getAvailablePort, tmpdir } from "../../utils/helpers"
@@ -219,7 +219,7 @@ describe("handleArgsSocketCatchError", () => {
219219
expect(logger.error).toHaveBeenCalledWith(errorMessage)
220220
})
221221

222-
it("should not log an error if its a iNodeJS.ErrnoException", () => {
222+
it("should not log an error if its a NodeJS.ErrnoException", () => {
223223
const error: NodeJS.ErrnoException = new Error()
224224
error.code = "ENOENT"
225225

@@ -250,3 +250,34 @@ describe("handleArgsSocketCatchError", () => {
250250
expect(logger.error).toHaveBeenCalledWith(error)
251251
})
252252
})
253+
254+
describe("listen", () => {
255+
let tmpDirPath: string
256+
let mockServer: http.Server
257+
258+
const testName = "listen"
259+
260+
beforeEach(async () => {
261+
await clean(testName)
262+
mockLogger()
263+
tmpDirPath = await tmpdir(testName)
264+
mockServer = http.createServer()
265+
})
266+
267+
afterEach(() => {
268+
mockServer.close()
269+
jest.clearAllMocks()
270+
})
271+
272+
it.only("should log an error if a directory is passed in instead of a file", async () => {
273+
const errorMessage = "EPERM: operation not permitted, unlink"
274+
const port = await getAvailablePort()
275+
const mockArgs = { port, host: "0.0.0.0", socket: tmpDirPath }
276+
try {
277+
await listen(mockServer, mockArgs)
278+
} catch (error) {}
279+
280+
expect(logger.error).toHaveBeenCalledTimes(1)
281+
expect(logger.error).toHaveBeenCalledWith(expect.stringContaining(errorMessage))
282+
})
283+
})

0 commit comments

Comments
 (0)