@@ -75,23 +75,26 @@ describe("Usbmux-client unit tests", () => {
75
75
76
76
it ( "should connect & report no connected devices initially" , async ( ) => {
77
77
client = new UsbmuxClient ( { port : mockServerPort ! } ) ;
78
+ const devicesPromise = client . getDevices ( ) ;
78
79
const socket = await waitForSocket ( ) ;
79
80
80
81
await expectMessage ( socket , 'LISTEN_REQUEST' ) ;
81
82
socket . write ( Buffer . from ( MESSAGES . OK_RESULT , 'base64' ) ) ;
82
83
;
83
- const devices = await client . getDevices ( ) ;
84
+ const devices = await devicesPromise ;
84
85
expect ( Object . keys ( devices ) ) . to . have . length ( 0 ) ;
85
86
} ) ;
86
87
87
88
it ( "should connect & report a connected device after one appears" , async ( ) => {
88
89
client = new UsbmuxClient ( { port : mockServerPort ! } ) ;
90
+ const devicesPromise = client . getDevices ( ) ;
89
91
const socket = await waitForSocket ( ) ;
90
92
91
93
await expectMessage ( socket , 'LISTEN_REQUEST' ) ;
92
94
socket . write ( Buffer . from ( MESSAGES . OK_RESULT , 'base64' ) ) ;
93
95
94
- expect ( Object . keys ( await client . getDevices ( ) ) ) . to . have . length ( 0 ) ;
96
+ const devices = await devicesPromise ;
97
+ expect ( Object . keys ( devices ) ) . to . have . length ( 0 ) ;
95
98
96
99
socket . write ( Buffer . from ( MESSAGES . DEVICE_ATTACHED_EVENT , 'base64' ) ) ;
97
100
await delay ( 10 ) ;
@@ -100,25 +103,26 @@ describe("Usbmux-client unit tests", () => {
100
103
101
104
it ( "should handle reconnecting after disconnection" , async ( ) => {
102
105
client = new UsbmuxClient ( { port : mockServerPort ! } ) ;
103
- let socket = await waitForSocket ( ) ;
106
+ const devicesPromise = client . getDevices ( ) ;
104
107
108
+ let socket = await waitForSocket ( ) ;
105
109
await expectMessage ( socket , 'LISTEN_REQUEST' ) ;
106
110
socket . write ( Buffer . from ( MESSAGES . OK_RESULT , 'base64' ) ) ;
107
111
108
- expect ( Object . keys ( await client . getDevices ( ) ) ) . to . have . length ( 0 ) ;
112
+ expect ( Object . keys ( await devicesPromise ) ) . to . have . length ( 0 ) ;
109
113
110
114
socket . destroy ( ) ;
111
115
serverSocket = undefined ;
112
116
await delay ( 10 ) ;
113
117
114
- const deviceQuery = client . getDevices ( ) ;
118
+ const device2ndQuery = client . getDevices ( ) ;
115
119
116
120
socket = await waitForSocket ( ) ;
117
121
await expectMessage ( socket , 'LISTEN_REQUEST' ) ;
118
122
socket . write ( Buffer . from ( MESSAGES . OK_RESULT , 'base64' ) ) ;
119
123
socket . write ( Buffer . from ( MESSAGES . DEVICE_ATTACHED_EVENT , 'base64' ) ) ;
120
124
121
- expect ( Object . keys ( await deviceQuery ) ) . to . have . length ( 1 ) ;
125
+ expect ( Object . keys ( await device2ndQuery ) ) . to . have . length ( 1 ) ;
122
126
} ) ;
123
127
124
128
it ( "should handle reconnecting to an initially unresponsive server" , async ( ) => {
@@ -127,7 +131,7 @@ describe("Usbmux-client unit tests", () => {
127
131
128
132
client = new UsbmuxClient ( { port } ) ;
129
133
130
- const deviceQueryResult = await client . getDevices ( ) . catch ( e => e ) ; ;
134
+ const deviceQueryResult = await client . getDevices ( ) . catch ( e => e ) ;
131
135
expect ( deviceQueryResult ) . to . be . instanceOf ( Error ) ;
132
136
expect ( deviceQueryResult . message ) . to . contain ( "ECONNREFUSED" ) ;
133
137
0 commit comments