@@ -8,15 +8,27 @@ describe("parseListeningPorts", () => {
88
99 // Sorted by port, so the lowest listener is first regardless of lsof order.
1010 expect ( parseListeningPorts ( output ) ) . toEqual ( [
11- { port : 5173 , processName : "node" , pid : 123 } ,
12- { port : 8000 , processName : "Python" , pid : 456 } ,
11+ { port : 5173 , processName : "node" , pid : 123 , probeHost : "127.0.0.1" } ,
12+ { port : 8000 , processName : "Python" , pid : 456 , probeHost : "127.0.0.1" } ,
1313 ] ) ;
1414 } ) ;
1515
16- it ( "collapses a port listed once per address family" , ( ) => {
17- const output = [ "p1" , "cnode" , "n*: 3000" , "n[::1] :3000" ] . join ( "\n" ) ;
16+ it ( "collapses a port listed once per address family, preferring IPv4 " , ( ) => {
17+ const output = [ "p1" , "cnode" , "n[::1]: 3000" , "n* :3000" ] . join ( "\n" ) ;
1818
19- expect ( parseListeningPorts ( output ) ) . toEqual ( [ { port : 3000 , processName : "node" , pid : 1 } ] ) ;
19+ expect ( parseListeningPorts ( output ) ) . toEqual ( [
20+ { port : 3000 , processName : "node" , pid : 1 , probeHost : "127.0.0.1" } ,
21+ ] ) ;
22+ } ) ;
23+
24+ it ( "keeps the IPv6 loopback for a listener bound only to ::1" , ( ) => {
25+ // Node resolving "localhost" to ::1 produces exactly this: a dev server
26+ // that refuses 127.0.0.1 but serves [::1] fine.
27+ const output = [ "p1" , "cnode" , "n[::1]:4321" ] . join ( "\n" ) ;
28+
29+ expect ( parseListeningPorts ( output ) ) . toEqual ( [
30+ { port : 4321 , processName : "node" , pid : 1 , probeHost : "::1" } ,
31+ ] ) ;
2032 } ) ;
2133
2234 it ( "ignores addresses this machine's browser cannot reach" , ( ) => {
@@ -35,8 +47,8 @@ describe("parseListeningPorts", () => {
3547 const output = [ "p1" , "cnode" , "n*:3000" , "p2" , "n*:4000" ] . join ( "\n" ) ;
3648
3749 expect ( parseListeningPorts ( output ) ) . toEqual ( [
38- { port : 3000 , processName : "node" , pid : 1 } ,
39- { port : 4000 , processName : "" , pid : 2 } ,
50+ { port : 3000 , processName : "node" , pid : 1 , probeHost : "127.0.0.1" } ,
51+ { port : 4000 , processName : "" , pid : 2 , probeHost : "127.0.0.1" } ,
4052 ] ) ;
4153 } ) ;
4254} ) ;
0 commit comments