@@ -3,7 +3,7 @@ import { promises } from "fs"
3
3
import * as http from "http"
4
4
import * as https from "https"
5
5
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"
7
7
import { OptionalString , setDefaults } from "../../../src/node/cli"
8
8
import { generateCertificate } from "../../../src/node/util"
9
9
import { clean , mockLogger , getAvailablePort , tmpdir } from "../../utils/helpers"
@@ -219,7 +219,7 @@ describe("handleArgsSocketCatchError", () => {
219
219
expect ( logger . error ) . toHaveBeenCalledWith ( errorMessage )
220
220
} )
221
221
222
- it ( "should not log an error if its a iNodeJS .ErrnoException" , ( ) => {
222
+ it ( "should not log an error if its a NodeJS .ErrnoException" , ( ) => {
223
223
const error : NodeJS . ErrnoException = new Error ( )
224
224
error . code = "ENOENT"
225
225
@@ -250,3 +250,34 @@ describe("handleArgsSocketCatchError", () => {
250
250
expect ( logger . error ) . toHaveBeenCalledWith ( error )
251
251
} )
252
252
} )
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