@@ -108,41 +108,47 @@ it('should emit error', async ({page, server, isFirefox}) => {
108
108
expect ( message ) . toContain ( ': 400' ) ;
109
109
} ) ;
110
110
111
- it ( 'should not have stray error events' , async ( { page, server, isFirefox} ) => {
112
- const [ ws ] = await Promise . all ( [
113
- page . waitForEvent ( 'websocket' ) ,
111
+ it ( 'should not have stray error events' , async ( { page, server} ) => {
112
+ let error ;
113
+ page . on ( 'websocket' , ws => ws . on ( 'socketerror' , e => error = e ) ) ;
114
+ await Promise . all ( [
115
+ page . waitForEvent ( 'websocket' ) . then ( async ws => {
116
+ await ws . waitForEvent ( 'framereceived' ) ;
117
+ return ws ;
118
+ } ) ,
114
119
page . evaluate ( port => {
115
120
( window as any ) . ws = new WebSocket ( 'ws://localhost:' + port + '/ws' ) ;
116
121
} , server . PORT )
117
122
] ) ;
118
- let error ;
119
- ws . on ( 'socketerror' , e => error = e ) ;
120
- await ws . waitForEvent ( 'framereceived' ) ;
121
123
await page . evaluate ( 'window.ws.close()' ) ;
122
124
expect ( error ) . toBeFalsy ( ) ;
123
125
} ) ;
124
126
125
- it ( 'should reject waitForEvent on socket close' , async ( { page, server, isFirefox } ) => {
127
+ it ( 'should reject waitForEvent on socket close' , async ( { page, server} ) => {
126
128
const [ ws ] = await Promise . all ( [
127
- page . waitForEvent ( 'websocket' ) ,
129
+ page . waitForEvent ( 'websocket' ) . then ( async ws => {
130
+ await ws . waitForEvent ( 'framereceived' ) ;
131
+ return ws ;
132
+ } ) ,
128
133
page . evaluate ( port => {
129
134
( window as any ) . ws = new WebSocket ( 'ws://localhost:' + port + '/ws' ) ;
130
135
} , server . PORT )
131
136
] ) ;
132
- await ws . waitForEvent ( 'framereceived' ) ;
133
137
const error = ws . waitForEvent ( 'framesent' ) . catch ( e => e ) ;
134
138
await page . evaluate ( 'window.ws.close()' ) ;
135
139
expect ( ( await error ) . message ) . toContain ( 'Socket closed' ) ;
136
140
} ) ;
137
141
138
- it ( 'should reject waitForEvent on page close' , async ( { page, server, isFirefox } ) => {
142
+ it ( 'should reject waitForEvent on page close' , async ( { page, server} ) => {
139
143
const [ ws ] = await Promise . all ( [
140
- page . waitForEvent ( 'websocket' ) ,
144
+ page . waitForEvent ( 'websocket' ) . then ( async ws => {
145
+ await ws . waitForEvent ( 'framereceived' ) ;
146
+ return ws ;
147
+ } ) ,
141
148
page . evaluate ( port => {
142
149
( window as any ) . ws = new WebSocket ( 'ws://localhost:' + port + '/ws' ) ;
143
150
} , server . PORT )
144
151
] ) ;
145
- await ws . waitForEvent ( 'framereceived' ) ;
146
152
const error = ws . waitForEvent ( 'framesent' ) . catch ( e => e ) ;
147
153
await page . close ( ) ;
148
154
expect ( ( await error ) . message ) . toContain ( 'Page closed' ) ;
0 commit comments