@@ -108,41 +108,47 @@ it('should emit error', async ({page, server, isFirefox}) => {
108108 expect ( message ) . toContain ( ': 400' ) ;
109109} ) ;
110110
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+ } ) ,
114119 page . evaluate ( port => {
115120 ( window as any ) . ws = new WebSocket ( 'ws://localhost:' + port + '/ws' ) ;
116121 } , server . PORT )
117122 ] ) ;
118- let error ;
119- ws . on ( 'socketerror' , e => error = e ) ;
120- await ws . waitForEvent ( 'framereceived' ) ;
121123 await page . evaluate ( 'window.ws.close()' ) ;
122124 expect ( error ) . toBeFalsy ( ) ;
123125} ) ;
124126
125- it ( 'should reject waitForEvent on socket close' , async ( { page, server, isFirefox } ) => {
127+ it ( 'should reject waitForEvent on socket close' , async ( { page, server} ) => {
126128 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+ } ) ,
128133 page . evaluate ( port => {
129134 ( window as any ) . ws = new WebSocket ( 'ws://localhost:' + port + '/ws' ) ;
130135 } , server . PORT )
131136 ] ) ;
132- await ws . waitForEvent ( 'framereceived' ) ;
133137 const error = ws . waitForEvent ( 'framesent' ) . catch ( e => e ) ;
134138 await page . evaluate ( 'window.ws.close()' ) ;
135139 expect ( ( await error ) . message ) . toContain ( 'Socket closed' ) ;
136140} ) ;
137141
138- it ( 'should reject waitForEvent on page close' , async ( { page, server, isFirefox } ) => {
142+ it ( 'should reject waitForEvent on page close' , async ( { page, server} ) => {
139143 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+ } ) ,
141148 page . evaluate ( port => {
142149 ( window as any ) . ws = new WebSocket ( 'ws://localhost:' + port + '/ws' ) ;
143150 } , server . PORT )
144151 ] ) ;
145- await ws . waitForEvent ( 'framereceived' ) ;
146152 const error = ws . waitForEvent ( 'framesent' ) . catch ( e => e ) ;
147153 await page . close ( ) ;
148154 expect ( ( await error ) . message ) . toContain ( 'Page closed' ) ;
0 commit comments