|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +constos=require("os"); |
3 | 4 | const{ testBin, normalizeStderr}=require("../helpers/test-bin"); |
4 | 5 | constport=require("../ports-map")["cli-host"]; |
5 | 6 | constServer=require("../../lib/Server"); |
@@ -116,6 +117,127 @@ describe('"host" CLI option', () => { |
116 | 117 | expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); |
117 | 118 | }); |
118 | 119 |
|
| 120 | +it('should work using "--host local-ip" take the first network found',async()=>{ |
| 121 | +const{ exitCode, stderr}=awaittestBin([ |
| 122 | +"--port", |
| 123 | +port, |
| 124 | +"--host", |
| 125 | +"local-ip", |
| 126 | +]); |
| 127 | + |
| 128 | +expect(exitCode).toEqual(0); |
| 129 | +jest.spyOn(os,"networkInterfaces").mockImplementation(()=>{ |
| 130 | +return{ |
| 131 | +lo:[ |
| 132 | +{ |
| 133 | +address:"127.0.0.1", |
| 134 | +netmask:"255.0.0.0", |
| 135 | +family:"IPv4", |
| 136 | +mac:"00:00:00:00:00:00", |
| 137 | +internal:true, |
| 138 | +cidr:"127.0.0.1/8", |
| 139 | +}, |
| 140 | +{ |
| 141 | +address:"::1", |
| 142 | +netmask:"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", |
| 143 | +family:"IPv6", |
| 144 | +mac:"00:00:00:00:00:00", |
| 145 | +internal:true, |
| 146 | +cidr:"::1/128", |
| 147 | +scopeid:0, |
| 148 | +}, |
| 149 | +], |
| 150 | +enp6s0:[ |
| 151 | +{ |
| 152 | +address:"192.168.1.15", |
| 153 | +netmask:"255.255.255.0", |
| 154 | +family:"IPv4", |
| 155 | +mac:"50:eb:f6:97:9f:6f", |
| 156 | +internal:false, |
| 157 | +cidr:"192.168.1.15/24", |
| 158 | +}, |
| 159 | +{ |
| 160 | +address:"2a01:cb0c:1623:6800:4ff8:723c:1a4b:fe5d", |
| 161 | +netmask:"ffff:ffff:ffff:ffff::", |
| 162 | +family:"IPv6", |
| 163 | +mac:"50:eb:f6:97:9f:6f", |
| 164 | +internal:false, |
| 165 | +cidr:"2a01:cb0c:1623:6800:4ff8:723c:1a4b:fe5d/64", |
| 166 | +scopeid:0, |
| 167 | +}, |
| 168 | +{ |
| 169 | +address:"2a01:cb0c:1623:6800:9acc:408c:ee87:27cf", |
| 170 | +netmask:"ffff:ffff:ffff:ffff::", |
| 171 | +family:"IPv6", |
| 172 | +mac:"50:eb:f6:97:9f:6f", |
| 173 | +internal:false, |
| 174 | +cidr:"2a01:cb0c:1623:6800:9acc:408c:ee87:27cf/64", |
| 175 | +scopeid:0, |
| 176 | +}, |
| 177 | +{ |
| 178 | +address:"fe80::bf2a:e5e2:8f9:4336", |
| 179 | +netmask:"ffff:ffff:ffff:ffff::", |
| 180 | +family:"IPv6", |
| 181 | +mac:"50:eb:f6:97:9f:6f", |
| 182 | +internal:false, |
| 183 | +cidr:"fe80::bf2a:e5e2:8f9:4336/64", |
| 184 | +scopeid:2, |
| 185 | +}, |
| 186 | +], |
| 187 | +"br-9bb0264f9b1c":[ |
| 188 | +{ |
| 189 | +address:"172.19.0.1", |
| 190 | +netmask:"255.255.0.0", |
| 191 | +family:"IPv4", |
| 192 | +mac:"02:42:e4:c8:6e:5f", |
| 193 | +internal:false, |
| 194 | +cidr:"172.19.0.1/16", |
| 195 | +}, |
| 196 | +{ |
| 197 | +address:"fe80::42:e4ff:fec8:6e5f", |
| 198 | +netmask:"ffff:ffff:ffff:ffff::", |
| 199 | +family:"IPv6", |
| 200 | +mac:"02:42:e4:c8:6e:5f", |
| 201 | +internal:false, |
| 202 | +cidr:"fe80::42:e4ff:fec8:6e5f/64", |
| 203 | +scopeid:4, |
| 204 | +}, |
| 205 | +], |
| 206 | +"br-a52e5d90701f":[ |
| 207 | +{ |
| 208 | +address:"172.18.0.1", |
| 209 | +netmask:"255.255.0.0", |
| 210 | +family:"IPv4", |
| 211 | +mac:"02:42:f6:7e:a2:45", |
| 212 | +internal:false, |
| 213 | +cidr:"172.18.0.1/16", |
| 214 | +}, |
| 215 | +{ |
| 216 | +address:"fe80::42:f6ff:fe7e:a245", |
| 217 | +netmask:"ffff:ffff:ffff:ffff::", |
| 218 | +family:"IPv6", |
| 219 | +mac:"02:42:f6:7e:a2:45", |
| 220 | +internal:false, |
| 221 | +cidr:"fe80::42:f6ff:fe7e:a245/64", |
| 222 | +scopeid:5, |
| 223 | +}, |
| 224 | +], |
| 225 | +docker0:[ |
| 226 | +{ |
| 227 | +address:"172.17.0.1", |
| 228 | +netmask:"255.255.0.0", |
| 229 | +family:"IPv4", |
| 230 | +mac:"02:42:3e:89:61:cf", |
| 231 | +internal:false, |
| 232 | +cidr:"172.17.0.1/16", |
| 233 | +}, |
| 234 | +], |
| 235 | +}; |
| 236 | +}); |
| 237 | +expect(stderr.indexOf("172.17.0.1")===-1); |
| 238 | +expect(stderr.indexOf("192.168.1.15")>-1); |
| 239 | +}); |
| 240 | + |
119 | 241 | it('should work using "--host local-ipv4"',async()=>{ |
120 | 242 | const{ exitCode, stderr}=awaittestBin([ |
121 | 243 | "--port", |
|