11'use strict' ;
22const { describe, specify, before} = require ( 'mocha-sugar-free' ) ;
3- const { assert : { lengthOf, deepEqual : deq , strictEqual : eq , approximately, isAtLeast, isAtMost, isString} } = require ( 'chai' ) ;
3+ const { assert : { lengthOf, deepEqual : deq , strictEqual : eq , approximately, isAtLeast, isAtMost, isString, isOk } } = require ( 'chai' ) ;
44const { stat} = require ( 'fs-extra' ) ;
55const { join : pathJoin } = require ( 'path' ) ;
66
@@ -9,6 +9,23 @@ const {runScriptFromFunction, testServerPort} = require('../utilities/integratio
99const httpEventFilter = e => e . type === 'http' ;
1010const httpEventNoFaviconFilter = e => httpEventFilter ( e ) && ! / \/ f a v i c o n .i c o $ / . test ( e . metaData . url ) ;
1111
12+ const assertCommonChildEvents = event => {
13+ const sendRequestEvent = event . children . find ( e => e . type === 'http:sendRequest' ) ;
14+ isOk ( sendRequestEvent ) ;
15+ isAtLeast ( sendRequestEvent . timing . begin . time , event . timing . begin . time ) ;
16+ isAtMost ( sendRequestEvent . timing . begin . time , event . timing . end . time ) ;
17+ isAtLeast ( sendRequestEvent . timing . end . time , sendRequestEvent . timing . begin . time ) ;
18+ isAtMost ( sendRequestEvent . timing . end . time , event . timing . end . time ) ;
19+
20+ const receiveResponseEvent = event . children . find ( e => e . type === 'http:receiveResponse' ) ;
21+ isOk ( receiveResponseEvent ) ;
22+ isAtLeast ( receiveResponseEvent . timing . begin . time , event . timing . begin . time ) ;
23+ isAtMost ( receiveResponseEvent . timing . begin . time , event . timing . end . time ) ;
24+ isAtLeast ( receiveResponseEvent . timing . end . time , receiveResponseEvent . timing . begin . time ) ;
25+ isAtMost ( receiveResponseEvent . timing . end . time , event . timing . end . time ) ;
26+ isAtLeast ( receiveResponseEvent . timing . begin . time , sendRequestEvent . timing . end . time ) ;
27+ } ;
28+
1229describe ( 'integration/httpEvents' , { timeout : 60000 , slow : 20000 } , ( ) => {
1330 let STATIC_HTML_SIZE ;
1431 let FOO_JPG_SIZE ;
@@ -104,6 +121,9 @@ describe('integration/httpEvents', {timeout: 60000, slow: 20000}, () => {
104121 eq ( event . metaData . fromCache , false ) ;
105122 eq ( event . metaData . redirectUrl , null ) ;
106123 eq ( event . metaData . statusLine , 'HTTP/1.1 200 OK' ) ;
124+
125+ lengthOf ( event . children , 2 ) ;
126+ assertCommonChildEvents ( event ) ;
107127 }
108128 } ) ;
109129
@@ -152,6 +172,7 @@ describe('integration/httpEvents', {timeout: 60000, slow: 20000}, () => {
152172 eq ( redirectedEvent . metaData . type , 'main_frame' ) ;
153173 eq ( redirectedEvent . metaData . statusCode , 200 ) ;
154174
175+ assertCommonChildEvents ( redirectedEvent ) ;
155176 const redirectChildEvents = redirectedEvent . children . filter ( e => e . type === 'http:redirect' ) ;
156177 lengthOf ( redirectChildEvents , 1 ) ;
157178 eq ( redirectChildEvents [ 0 ] . metaData . redirectUrl , `http://${ host } /static/static.html?waitBeforeResponse=50` ) ;
@@ -302,20 +323,7 @@ describe('integration/httpEvents', {timeout: 60000, slow: 20000}, () => {
302323 eq ( event . metaData . statusLine , 'HTTP/1.1 200 OK' ) ;
303324
304325 lengthOf ( event . children , 2 ) ;
305- const sendRequestEvent = event . children [ 0 ] ;
306- eq ( sendRequestEvent . type , 'http:sendRequest' ) ;
307- isAtLeast ( sendRequestEvent . timing . begin . time , event . timing . begin . time ) ;
308- isAtMost ( sendRequestEvent . timing . begin . time , event . timing . end . time ) ;
309- isAtLeast ( sendRequestEvent . timing . end . time , sendRequestEvent . timing . begin . time ) ;
310- isAtMost ( sendRequestEvent . timing . end . time , event . timing . end . time ) ;
311-
312- const receiveResponseEvent = event . children [ 1 ] ;
313- eq ( receiveResponseEvent . type , 'http:receiveResponse' ) ;
314- isAtLeast ( receiveResponseEvent . timing . begin . time , event . timing . begin . time ) ;
315- isAtMost ( receiveResponseEvent . timing . begin . time , event . timing . end . time ) ;
316- isAtLeast ( receiveResponseEvent . timing . end . time , receiveResponseEvent . timing . begin . time ) ;
317- isAtMost ( receiveResponseEvent . timing . end . time , event . timing . end . time ) ;
318- isAtLeast ( receiveResponseEvent . timing . begin . time , sendRequestEvent . timing . end . time ) ;
326+ assertCommonChildEvents ( event ) ;
319327 }
320328 } ) ;
321329
@@ -351,5 +359,8 @@ describe('integration/httpEvents', {timeout: 60000, slow: 20000}, () => {
351359 eq ( events [ 0 ] . metaData . url , `${ urlPrefix } /fetchWorker.html` ) ;
352360 eq ( events [ 1 ] . metaData . url , `${ urlPrefix } /js/fetchWorker.js` ) ;
353361 eq ( events [ 2 ] . metaData . url , `${ urlPrefix } /static.html?fromWorker` ) ;
362+ assertCommonChildEvents ( events [ 0 ] ) ;
363+ assertCommonChildEvents ( events [ 1 ] ) ;
364+ assertCommonChildEvents ( events [ 2 ] ) ;
354365 } ) ;
355366} ) ;
0 commit comments