11import { describe , it , iit , xit , expect , beforeEach , afterEach } from 'angular2/test_lib' ;
22
3- import { isBlank , isPresent , BaseException , stringify } from 'angular2/src/facade/lang' ;
3+ import { isBlank , isPresent , BaseException , stringify , Date , DateWrapper } from 'angular2/src/facade/lang' ;
44import { ListWrapper , List } from 'angular2/src/facade/collection' ;
55import { PromiseWrapper , Promise } from 'angular2/src/facade/async' ;
66
77import {
88 Sampler , WebDriverAdapter , WebDriverExtension ,
99 Validator , Metric , Reporter , Browser ,
10- bind , Injector , Options
10+ bind , Injector , Options , MeasureValues
1111} from 'benchpress/benchpress' ;
1212
1313export function main ( ) {
@@ -26,6 +26,7 @@ export function main() {
2626 prepare,
2727 execute
2828 } = { } ) {
29+ var time = 1000 ;
2930 if ( isBlank ( metric ) ) {
3031 metric = new MockMetric ( [ ] ) ;
3132 }
@@ -44,7 +45,8 @@ export function main() {
4445 bind ( WebDriverAdapter ) . toValue ( driver ) ,
4546 bind ( WebDriverExtension ) . toValue ( driverExtension ) ,
4647 bind ( Options . EXECUTE ) . toValue ( execute ) ,
47- bind ( Validator ) . toValue ( validator )
48+ bind ( Validator ) . toValue ( validator ) ,
49+ bind ( Sampler . TIME ) . toValue ( ( ) => DateWrapper . fromMillis ( time ++ ) )
4850 ] ) ;
4951 if ( isPresent ( prepare ) ) {
5052 ListWrapper . push ( bindings , bind ( Options . PREPARE ) . toValue ( prepare ) ) ;
@@ -181,8 +183,8 @@ export function main() {
181183 } ) ;
182184 sampler . sample ( ) . then ( ( state ) => {
183185 expect ( state . completeSample . length ) . toBe ( 2 ) ;
184- expect ( state . completeSample [ 0 ] ) . toEqual ( { 'script' : 10 } ) ;
185- expect ( state . completeSample [ 1 ] ) . toEqual ( { 'script' : 20 } ) ;
186+ expect ( state . completeSample [ 0 ] ) . toEqual ( mv ( 0 , 1000 , { 'script' : 10 } ) ) ;
187+ expect ( state . completeSample [ 1 ] ) . toEqual ( mv ( 1 , 1001 , { 'script' : 20 } ) ) ;
186188 done ( ) ;
187189 } ) ;
188190 } ) ;
@@ -206,10 +208,10 @@ export function main() {
206208
207209 expect ( log . length ) . toBe ( 2 ) ;
208210 expect ( log [ 0 ] ) . toEqual (
209- [ 'validate' , [ { 'script' : 0 } ] , null ]
211+ [ 'validate' , [ mv ( 0 , 1000 , { 'script' : 0 } ) ] , null ]
210212 ) ;
211213 expect ( log [ 1 ] ) . toEqual (
212- [ 'validate' , [ { 'script' : 0 } , { 'script' : 1 } ] , validSample ]
214+ [ 'validate' , [ mv ( 0 , 1000 , { 'script' : 0 } ) , mv ( 1 , 1001 , { 'script' : 1 } ) ] , validSample ]
213215 ) ;
214216
215217 done ( ) ;
@@ -234,13 +236,13 @@ export function main() {
234236 // ]);
235237 expect ( log . length ) . toBe ( 3 ) ;
236238 expect ( log [ 0 ] ) . toEqual (
237- [ 'reportMeasureValues' , 0 , { 'script' : 0 } ]
239+ [ 'reportMeasureValues' , mv ( 0 , 1000 , { 'script' : 0 } ) ]
238240 ) ;
239241 expect ( log [ 1 ] ) . toEqual (
240- [ 'reportMeasureValues' , 1 , { 'script' : 1 } ]
242+ [ 'reportMeasureValues' , mv ( 1 , 1001 , { 'script' : 1 } ) ]
241243 ) ;
242244 expect ( log [ 2 ] ) . toEqual (
243- [ 'reportSample' , [ { 'script' : 0 } , { 'script' : 1 } ] , validSample ]
245+ [ 'reportSample' , [ mv ( 0 , 1000 , { 'script' : 0 } ) , mv ( 1 , 1001 , { 'script' : 1 } ) ] , validSample ]
244246 ) ;
245247
246248 done ( ) ;
@@ -250,6 +252,10 @@ export function main() {
250252 } ) ;
251253}
252254
255+ function mv ( runIndex , time , values ) {
256+ return new MeasureValues ( runIndex , DateWrapper . fromMillis ( time ) , values ) ;
257+ }
258+
253259function createCountingValidator ( count , validSample = null , log = null ) {
254260 return new MockValidator ( log , ( completeSample ) => {
255261 count -- ;
@@ -315,7 +321,7 @@ class MockValidator extends Validator {
315321 }
316322 this . _log = log ;
317323 }
318- validate ( completeSample :List < Object > ) :List < Object > {
324+ validate ( completeSample :List < MeasureValues > ) :List < MeasureValues > {
319325 var stableSample = isPresent ( this . _validate ) ? this . _validate ( completeSample ) : completeSample ;
320326 ListWrapper . push ( this . _log , [ 'validate' , completeSample , stableSample ] ) ;
321327 return stableSample ;
@@ -353,8 +359,8 @@ class MockReporter extends Reporter {
353359 }
354360 this . _log = log ;
355361 }
356- reportMeasureValues ( index , values ) :Promise {
357- ListWrapper . push ( this . _log , [ 'reportMeasureValues' , index , values ] ) ;
362+ reportMeasureValues ( values ) :Promise {
363+ ListWrapper . push ( this . _log , [ 'reportMeasureValues' , values ] ) ;
358364 return PromiseWrapper . resolve ( null ) ;
359365 }
360366 reportSample ( completeSample , validSample ) :Promise {
0 commit comments