@@ -15,6 +15,10 @@ function close() { this.close(); }
15
15
// Test listen({port})
16
16
net . createServer ( ) . listen ( { port : 0 } )
17
17
. on ( 'listening' , common . mustCall ( close ) ) ;
18
+ // Test listen(host, port }) on ipv4
19
+ net . createServer ( ) . listen ( { host : '127.0.0.1' , port : '3000' } ) . on ( 'listening' , common . mustCall ( close ) ) ;
20
+ // Test listen(host, port }) on ipv6
21
+ net . createServer ( ) . listen ( { host : '::' , port : '3001' } ) . on ( 'listening' , common . mustCall ( close ) ) ;
18
22
}
19
23
20
24
// Test listen(port, cb) and listen({ port }, cb) combinations
@@ -66,6 +70,13 @@ const listenOnPort = [
66
70
name : 'TypeError' ,
67
71
message : / ^ T h e a r g u m e n t ' o p t i o n s ' m u s t h a v e t h e p r o p e r t y " p o r t " o r " p a t h " \. R e c e i v e d .+ $ / ,
68
72
} ) ;
73
+ } else if ( typeof options . host === 'string' && ! options . host . match ( / ^ [ a - z A - Z 0 - 9 - :% .] + $ / ) ) {
74
+ assert . throws ( fn ,
75
+ {
76
+ code : 'ERR_INVALID_ARG_VALUE' ,
77
+ name : 'TypeError' ,
78
+ message : / ^ T h e a r g u m e n t ' h o s t ' i s i n v a l i d \. R e c e i v e d .+ $ / ,
79
+ } ) ;
69
80
} else {
70
81
assert . throws ( fn ,
71
82
{
@@ -91,4 +102,5 @@ const listenOnPort = [
91
102
shouldFailToListen ( { host : 'localhost:3000' } ) ;
92
103
shouldFailToListen ( { host : { port : 3000 } } ) ;
93
104
shouldFailToListen ( { exclusive : true } ) ;
105
+ shouldFailToListen ( { host : '[::]' , port : 3000 } ) ;
94
106
}
0 commit comments