@@ -29,18 +29,6 @@ const CLIENT_FIXTURE = {
2929 didRunSuites : sinon . stub ( ) ,
3030} ;
3131
32- function stubPerformanceNowCalls ( syncStart , syncEnd , asyncStart , asyncEnd ) {
33- sinon
34- . stub ( window . performance , "now" )
35- . onFirstCall ( )
36- . returns ( syncStart ) // startTime (sync)
37- . onSecondCall ( )
38- . returns ( syncEnd ) // endTime (sync)
39- . onThirdCall ( )
40- . returns ( asyncStart ) // startTime (async)
41- . returns ( asyncEnd ) ; // endTime (async)
42- }
43-
4432describe ( "BenchmarkRunner" , ( ) => {
4533 const { spy, stub, assert } = sinon ;
4634 let runner ;
@@ -206,13 +194,12 @@ describe("BenchmarkRunner", () => {
206194 it ( "should write performance marks at the start and end of the test with the correct test name" , ( ) => {
207195 assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-start" ) ;
208196 assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-sync-end" ) ;
209- assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-async-start" ) ;
210197 assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-async-end" ) ;
211198
212199 // SuiteRunner adds 2 marks.
213200 // Suite used here contains 3 tests.
214- // Each Testrunner adds 4 marks.
215- expect ( performanceMarkSpy . callCount ) . to . equal ( 14 ) ;
201+ // Each TestRunner adds 3 marks.
202+ expect ( performanceMarkSpy . callCount ) . to . equal ( 11 ) ;
216203 } ) ;
217204 } ) ;
218205
@@ -222,7 +209,6 @@ describe("BenchmarkRunner", () => {
222209
223210 const syncStart = 8000 ;
224211 const syncEnd = 10000 ;
225- const asyncStart = 12000 ;
226212 const asyncEnd = 13000 ;
227213
228214 const params = { measurementMethod : "raf" } ;
@@ -232,7 +218,13 @@ describe("BenchmarkRunner", () => {
232218 tests : { } ,
233219 } ) ;
234220
235- stubPerformanceNowCalls ( syncStart , syncEnd , asyncStart , asyncEnd ) ;
221+ const originalMark = window . performance . mark . bind ( window . performance ) ;
222+ const performanceMarkStub = sinon . stub ( window . performance , "mark" ) . withArgs ( sinon . match . any ) . callThrough ( ) ;
223+ const performanceNowStub = sinon . stub ( window . performance , "now" ) ;
224+
225+ performanceNowStub . onFirstCall ( ) . returns ( syncStart ) ;
226+ performanceMarkStub . onThirdCall ( ) . callsFake ( ( markName ) => originalMark ( markName , { startTime : asyncEnd } ) ) ;
227+ performanceNowStub . onSecondCall ( ) . returns ( asyncEnd ) ;
236228
237229 // instantiate recorded test results
238230 const suiteRunner = new SuiteRunner ( runner . _frame , runner . _page , params , suite , runner . _client , runner . _measuredValues ) ;
@@ -243,7 +235,7 @@ describe("BenchmarkRunner", () => {
243235
244236 it ( "should calculate measured test values correctly" , ( ) => {
245237 const syncTime = syncEnd - syncStart ;
246- const asyncTime = asyncEnd - asyncStart ;
238+ const asyncTime = asyncEnd - syncEnd ;
247239
248240 const total = syncTime + asyncTime ;
249241 const mean = total / suite . tests . length ;
0 commit comments