| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  | import { | 
					
						
							|  |  |  |   afterEach, | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | import { | 
					
						
							|  |  |  |   Runner, Sampler, SampleDescription, | 
					
						
							|  |  |  |   Validator, bind, Injector, Metric, | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |   Options, WebDriverAdapter | 
					
						
							| 
									
										
										
										
											2015-03-02 09:23:09 -08:00
										 |  |  | } from 'benchpress/common'; | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | import { isBlank } from 'angular2/src/facade/lang'; | 
					
						
							|  |  |  | import { Promise, PromiseWrapper } from 'angular2/src/facade/async'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('runner', () => { | 
					
						
							|  |  |  |     var injector; | 
					
						
							|  |  |  |     var runner; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function createRunner(defaultBindings = null) { | 
					
						
							|  |  |  |       if (isBlank(defaultBindings)) { | 
					
						
							|  |  |  |         defaultBindings = []; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       runner = new Runner([ | 
					
						
							|  |  |  |         defaultBindings, | 
					
						
							|  |  |  |         bind(Sampler).toFactory( | 
					
						
							|  |  |  |           (_injector) => { | 
					
						
							|  |  |  |             injector = _injector; | 
					
						
							|  |  |  |             return new MockSampler(); | 
					
						
							|  |  |  |           }, [Injector] | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         bind(Metric).toFactory( () => new MockMetric(), []), | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |         bind(Validator).toFactory( () => new MockValidator(), []), | 
					
						
							|  |  |  |         bind(WebDriverAdapter).toFactory( () => new MockWebDriverAdapter(), []) | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       ]); | 
					
						
							|  |  |  |       return runner; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should set SampleDescription.id', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       createRunner().sample({id: 'someId'}) | 
					
						
							|  |  |  |         .then( (_) => injector.asyncGet(SampleDescription) ) | 
					
						
							|  |  |  |         .then( (desc) => { | 
					
						
							|  |  |  |           expect(desc.id).toBe('someId'); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |           async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       createRunner([ | 
					
						
							|  |  |  |         bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1}) | 
					
						
							|  |  |  |       ]).sample({id: 'someId', bindings: [ | 
					
						
							|  |  |  |         bind(Options.SAMPLE_DESCRIPTION).toValue({'b': 2}) | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       ]}).then( (_) => injector.asyncGet(SampleDescription) ) | 
					
						
							|  |  |  |          .then( (desc) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(desc.description).toEqual({ | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |           'forceGc': false, | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |           'userAgent': 'someUserAgent', | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |           'a': 1, | 
					
						
							|  |  |  |           'b': 2, | 
					
						
							|  |  |  |           'v': 11 | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should fill SampleDescription.metrics from the Metric', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       createRunner().sample({id: 'someId'}) | 
					
						
							|  |  |  |         .then( (_) => injector.asyncGet(SampleDescription) ) | 
					
						
							|  |  |  |         .then( (desc) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(desc.metrics).toEqual({ 'm1': 'some metric' }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should bind Options.EXECUTE', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       var execute = () => {}; | 
					
						
							|  |  |  |       createRunner().sample({id: 'someId', execute: execute}).then( (_) => { | 
					
						
							|  |  |  |         expect(injector.get(Options.EXECUTE)).toEqual(execute); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should bind Options.PREPARE', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       var prepare = () => {}; | 
					
						
							|  |  |  |       createRunner().sample({id: 'someId', prepare: prepare}).then( (_) => { | 
					
						
							|  |  |  |         expect(injector.get(Options.PREPARE)).toEqual(prepare); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-03-03 11:31:35 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-03-03 11:31:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-27 10:37:02 -07:00
										 |  |  |     it('should bind Options.MICRO_METRICS', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |       createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then( (_) => { | 
					
						
							|  |  |  |         expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'}); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     it('should overwrite bindings per sample call', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       createRunner([ | 
					
						
							|  |  |  |         bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1}), | 
					
						
							|  |  |  |       ]).sample({id: 'someId', bindings: [ | 
					
						
							|  |  |  |         bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 2}), | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  |       ]}).then( (_) => injector.asyncGet(SampleDescription) ) | 
					
						
							|  |  |  |          .then( (desc) => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |         expect(injector.get(SampleDescription).description['a']).toBe(2); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |         async.done(); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-20 13:32:54 -08:00
										 |  |  | class MockWebDriverAdapter extends WebDriverAdapter { | 
					
						
							|  |  |  |   executeScript(script):Promise { | 
					
						
							|  |  |  |     return PromiseWrapper.resolve('someUserAgent'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 10:13:49 -08:00
										 |  |  | class MockValidator extends Validator { | 
					
						
							|  |  |  |   constructor() { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   describe() { | 
					
						
							|  |  |  |     return { 'v': 11 }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockMetric extends Metric { | 
					
						
							|  |  |  |   constructor() { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   describe() { | 
					
						
							|  |  |  |     return { 'm1': 'some metric' }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockSampler extends Sampler { | 
					
						
							|  |  |  |   constructor() { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   sample():Promise { | 
					
						
							|  |  |  |     return PromiseWrapper.resolve(23); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |