@@ -29,18 +29,6 @@ const CLIENT_FIXTURE = {
29
29
didRunSuites : sinon . stub ( ) ,
30
30
} ;
31
31
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
-
44
32
describe ( "BenchmarkRunner" , ( ) => {
45
33
const { spy, stub, assert } = sinon ;
46
34
let runner ;
@@ -206,13 +194,12 @@ describe("BenchmarkRunner", () => {
206
194
it ( "should write performance marks at the start and end of the test with the correct test name" , ( ) => {
207
195
assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-start" ) ;
208
196
assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-sync-end" ) ;
209
- assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-async-start" ) ;
210
197
assert . calledWith ( performanceMarkSpy , "Suite 1.Test 1-async-end" ) ;
211
198
212
199
// SuiteRunner adds 2 marks.
213
200
// 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 ) ;
216
203
} ) ;
217
204
} ) ;
218
205
@@ -222,7 +209,6 @@ describe("BenchmarkRunner", () => {
222
209
223
210
const syncStart = 8000 ;
224
211
const syncEnd = 10000 ;
225
- const asyncStart = 12000 ;
226
212
const asyncEnd = 13000 ;
227
213
228
214
const params = { measurementMethod : "raf" } ;
@@ -232,7 +218,13 @@ describe("BenchmarkRunner", () => {
232
218
tests : { } ,
233
219
} ) ;
234
220
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 ) ;
236
228
237
229
// instantiate recorded test results
238
230
const suiteRunner = new SuiteRunner ( runner . _frame , runner . _page , params , suite , runner . _client , runner . _measuredValues ) ;
@@ -243,7 +235,7 @@ describe("BenchmarkRunner", () => {
243
235
244
236
it ( "should calculate measured test values correctly" , ( ) => {
245
237
const syncTime = syncEnd - syncStart ;
246
- const asyncTime = asyncEnd - asyncStart ;
238
+ const asyncTime = asyncEnd - syncEnd ;
247
239
248
240
const total = syncTime + asyncTime ;
249
241
const mean = total / suite . tests . length ;
0 commit comments