@@ -10,7 +10,7 @@ const debug = debugModule('cypress:network:connect')
10
10
11
11
export function byPortAndAddress ( port : number , address : net . Address ) {
12
12
// https://nodejs.org/api/net.html#net_net_connect_port_host_connectlistener
13
- return new Bluebird < net . Address > ( ( resolve , reject ) => {
13
+ return new Promise < net . Address > ( ( resolve , reject ) => {
14
14
const onConnect = ( ) => {
15
15
client . destroy ( )
16
16
resolve ( address )
@@ -22,11 +22,9 @@ export function byPortAndAddress (port: number, address: net.Address) {
22
22
} )
23
23
}
24
24
25
- export function getAddress ( port : number , hostname : string ) : Bluebird < net . Address > {
25
+ export async function getAddress ( port : number , hostname : string ) : Promise < net . Address > {
26
26
debug ( 'beginning getAddress %o' , { hostname, port } )
27
27
28
- const fn = byPortAndAddress . bind ( { } , port )
29
-
30
28
// promisify at the very last second which enables us to
31
29
// modify dns lookup function (via hosts overrides)
32
30
const lookupAsync = Bluebird . promisify < LookupAddress [ ] , string , LookupAllOptions > ( dns . lookup , { context : dns } )
@@ -35,27 +33,31 @@ export function getAddress (port: number, hostname: string): Bluebird<net.Addres
35
33
// out the addresses. in fact it respects the /etc/hosts file
36
34
// https://github.com/nodejs/node/blob/dbdbdd4998e163deecefbb1d34cda84f749844a4/lib/dns.js#L108
37
35
// https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback
38
- // @ts -ignore
39
- return lookupAsync ( hostname , { all : true } )
40
- . then ( ( addresses ) => {
41
- debug ( 'got addresses %o' , { hostname, port, addresses } )
42
-
43
- // ipv6 addresses are causing problems with cypress in cypress internal e2e tests
44
- // on windows, so we are filtering them out here
45
- if ( process . env . CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT && os . platform ( ) === 'win32' ) {
46
- debug ( 'filtering ipv6 addresses %o' , { hostname, port, addresses } )
47
- addresses = addresses . filter ( ( address ) => {
48
- return address . family === 4
49
- } )
50
- }
51
36
52
- // convert to an array if string
53
- return Array . prototype . concat . call ( addresses ) . map ( fn )
54
- } )
55
- . tapCatch ( ( err ) => {
56
- debug ( 'error getting address %o' , { hostname, port, err } )
57
- } )
58
- . any ( )
37
+ let addresses = await lookupAsync ( hostname , { all : true } )
38
+
39
+ debug ( 'got addresses %o' , { hostname, port, addresses } )
40
+
41
+ // ipv6 addresses are causing problems with cypress in cypress internal e2e tests
42
+ // on windows, so we are filtering them out here
43
+ if ( process . env . CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT && os . platform ( ) === 'win32' ) {
44
+ debug ( 'filtering ipv6 addresses %o' , { hostname, port, addresses } )
45
+ addresses = addresses . filter ( ( address ) => {
46
+ return address . family === 4
47
+ } )
48
+ }
49
+
50
+ try {
51
+ const address = await Promise . any ( addresses . map ( ( address ) => {
52
+ return byPortAndAddress ( port , address as net . Address )
53
+ } ) )
54
+
55
+ return address
56
+ } catch ( error ) {
57
+ debug ( 'error getting address %o' , { hostname, port, error } )
58
+
59
+ throw error
60
+ }
59
61
}
60
62
61
63
export function getDelayForRetry ( iteration : number ) {
0 commit comments