fix(benchpress): Update types for TypeScript nullability support
This commit is contained in:
		
							parent
							
								
									075f3f8c9f
								
							
						
					
					
						commit
						14669f20bf
					
				| @ -4,6 +4,7 @@ | ||||
|   "description": "Benchpress - a framework for e2e performance tests", | ||||
|   "main": "index.js", | ||||
|   "typings": "./index.d.ts", | ||||
|   "strictNullChecks": true, | ||||
|   "dependencies": { | ||||
|     "@angular/core": "^2.0.0-rc.7", | ||||
|     "reflect-metadata": "^0.1.2", | ||||
|  | ||||
| @ -16,7 +16,7 @@ export function convertPerfProfileToEvents(perfProfile: any): any[] { | ||||
|   const finishedEvents: {[key: string]: any}[] = [];  // Event[] finished events
 | ||||
|   const addFinishedEvent = function(eventName: string, startTime: number, endTime: number) { | ||||
|     const categorizedEventName = categorizeEvent(eventName); | ||||
|     let args: {[key: string]: any} = undefined; | ||||
|     let args: {[key: string]: any}|undefined = undefined; | ||||
|     if (categorizedEventName == 'gc') { | ||||
|       // TODO: We cannot measure heap size at the moment
 | ||||
|       args = {usedHeapSize: 0}; | ||||
|  | ||||
| @ -140,11 +140,11 @@ export class PerflogMetric extends Metric { | ||||
|     const markName = this._markName(this._measureCount - 1); | ||||
|     const nextMarkName = restart ? this._markName(this._measureCount++) : null; | ||||
|     return this._driverExtension.timeEnd(markName, nextMarkName) | ||||
|         .then((_) => this._readUntilEndMark(markName)); | ||||
|         .then((_: any) => this._readUntilEndMark(markName)); | ||||
|   } | ||||
| 
 | ||||
|   private _readUntilEndMark( | ||||
|       markName: string, loopCount: number = 0, startEvent: PerfLogEvent = null) { | ||||
|       markName: string, loopCount: number = 0, startEvent: PerfLogEvent|null = null) { | ||||
|     if (loopCount > _MAX_RETRY_COUNT) { | ||||
|       throw new Error(`Tried too often to get the ending mark: ${loopCount}`); | ||||
|     } | ||||
| @ -175,7 +175,7 @@ export class PerflogMetric extends Metric { | ||||
|         } | ||||
|         startEvent['ph'] = 'B'; | ||||
|         endEvent['ph'] = 'E'; | ||||
|         endEvent['ts'] = startEvent['ts'] + startEvent['dur']; | ||||
|         endEvent['ts'] = startEvent['ts'] ! + startEvent['dur'] !; | ||||
|         this._remainingEvents.push(startEvent); | ||||
|         this._remainingEvents.push(endEvent); | ||||
|       } else { | ||||
| @ -185,13 +185,13 @@ export class PerflogMetric extends Metric { | ||||
|     if (needSort) { | ||||
|       // Need to sort because of the ph==='X' events
 | ||||
|       this._remainingEvents.sort((a, b) => { | ||||
|         const diff = a['ts'] - b['ts']; | ||||
|         const diff = a['ts'] ! - b['ts'] !; | ||||
|         return diff > 0 ? 1 : diff < 0 ? -1 : 0; | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private _aggregateEvents(events: PerfLogEvent[], markName: string): {[key: string]: number} { | ||||
|   private _aggregateEvents(events: PerfLogEvent[], markName: string): {[key: string]: number}|null { | ||||
|     const result: {[key: string]: number} = {'scriptTime': 0, 'pureScriptTime': 0}; | ||||
|     if (this._perfLogFeatures.gc) { | ||||
|       result['gcTime'] = 0; | ||||
| @ -217,8 +217,8 @@ export class PerflogMetric extends Metric { | ||||
|       result['requestCount'] = 0; | ||||
|     } | ||||
| 
 | ||||
|     let markStartEvent: PerfLogEvent = null; | ||||
|     let markEndEvent: PerfLogEvent = null; | ||||
|     let markStartEvent: PerfLogEvent = null !; | ||||
|     let markEndEvent: PerfLogEvent = null !; | ||||
|     events.forEach((event) => { | ||||
|       const ph = event['ph']; | ||||
|       const name = event['name']; | ||||
| @ -242,8 +242,8 @@ export class PerflogMetric extends Metric { | ||||
| 
 | ||||
|     const frameTimestamps: number[] = []; | ||||
|     const frameTimes: number[] = []; | ||||
|     let frameCaptureStartEvent: PerfLogEvent = null; | ||||
|     let frameCaptureEndEvent: PerfLogEvent = null; | ||||
|     let frameCaptureStartEvent: PerfLogEvent|null = null; | ||||
|     let frameCaptureEndEvent: PerfLogEvent|null = null; | ||||
| 
 | ||||
|     const intervalStarts: {[key: string]: PerfLogEvent} = {}; | ||||
|     const intervalStartCount: {[key: string]: number} = {}; | ||||
| @ -251,7 +251,7 @@ export class PerflogMetric extends Metric { | ||||
|     let inMeasureRange = false; | ||||
|     events.forEach((event) => { | ||||
|       const ph = event['ph']; | ||||
|       let name = event['name']; | ||||
|       let name = event['name'] !; | ||||
|       let microIterations = 1; | ||||
|       const microIterationsMatch = name.match(_MICRO_ITERATIONS_REGEX); | ||||
|       if (microIterationsMatch) { | ||||
| @ -270,7 +270,7 @@ export class PerflogMetric extends Metric { | ||||
|       if (this._requestCount && name === 'sendRequest') { | ||||
|         result['requestCount'] += 1; | ||||
|       } else if (this._receivedData && name === 'receivedData' && ph === 'I') { | ||||
|         result['receivedData'] += event['args']['encodedDataLength']; | ||||
|         result['receivedData'] += event['args'] !['encodedDataLength'] !; | ||||
|       } | ||||
|       if (ph === 'B' && name === _MARK_NAME_FRAME_CAPTURE) { | ||||
|         if (frameCaptureStartEvent) { | ||||
| @ -289,7 +289,7 @@ export class PerflogMetric extends Metric { | ||||
|       } | ||||
| 
 | ||||
|       if (ph === 'I' && frameCaptureStartEvent && !frameCaptureEndEvent && name === 'frame') { | ||||
|         frameTimestamps.push(event['ts']); | ||||
|         frameTimestamps.push(event['ts'] !); | ||||
|         if (frameTimestamps.length >= 2) { | ||||
|           frameTimes.push( | ||||
|               frameTimestamps[frameTimestamps.length - 1] - | ||||
| @ -308,14 +308,14 @@ export class PerflogMetric extends Metric { | ||||
|         intervalStartCount[name]--; | ||||
|         if (intervalStartCount[name] === 0) { | ||||
|           const startEvent = intervalStarts[name]; | ||||
|           const duration = (event['ts'] - startEvent['ts']); | ||||
|           intervalStarts[name] = null; | ||||
|           const duration = (event['ts'] ! - startEvent['ts'] !); | ||||
|           intervalStarts[name] = null !; | ||||
|           if (name === 'gc') { | ||||
|             result['gcTime'] += duration; | ||||
|             const amount = | ||||
|                 (startEvent['args']['usedHeapSize'] - event['args']['usedHeapSize']) / 1000; | ||||
|                 (startEvent['args'] !['usedHeapSize'] ! - event['args'] !['usedHeapSize'] !) / 1000; | ||||
|             result['gcAmount'] += amount; | ||||
|             const majorGc = event['args']['majorGc']; | ||||
|             const majorGc = event['args'] !['majorGc']; | ||||
|             if (majorGc && majorGc) { | ||||
|               result['majorGcTime'] += duration; | ||||
|             } | ||||
|  | ||||
| @ -48,7 +48,7 @@ export class Sampler { | ||||
|   } | ||||
| 
 | ||||
|   private _iterate(lastState: SampleState): Promise<SampleState> { | ||||
|     let resultPromise: Promise<SampleState>; | ||||
|     let resultPromise: Promise<SampleState|null>; | ||||
|     if (this._prepare !== Options.NO_PREPARE) { | ||||
|       resultPromise = this._driver.waitFor(this._prepare); | ||||
|     } else { | ||||
| @ -76,5 +76,5 @@ export class Sampler { | ||||
| } | ||||
| 
 | ||||
| export class SampleState { | ||||
|   constructor(public completeSample: MeasureValues[], public validSample: MeasureValues[]) {} | ||||
|   constructor(public completeSample: MeasureValues[], public validSample: MeasureValues[]|null) {} | ||||
| } | ||||
|  | ||||
| @ -17,7 +17,7 @@ export abstract class Validator { | ||||
|   /** | ||||
|    * Calculates a valid sample out of the complete sample | ||||
|    */ | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[] { throw new Error('NYI'); } | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[]|null { throw new Error('NYI'); } | ||||
| 
 | ||||
|   /** | ||||
|    * Returns a Map that describes the properties of the validator | ||||
|  | ||||
| @ -35,7 +35,7 @@ export class RegressionSlopeValidator extends Validator { | ||||
|     return {'sampleSize': this._sampleSize, 'regressionSlopeMetric': this._metric}; | ||||
|   } | ||||
| 
 | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[] { | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[]|null { | ||||
|     if (completeSample.length >= this._sampleSize) { | ||||
|       const latestSample = | ||||
|           completeSample.slice(completeSample.length - this._sampleSize, completeSample.length); | ||||
|  | ||||
| @ -23,7 +23,7 @@ export class SizeValidator extends Validator { | ||||
| 
 | ||||
|   describe(): {[key: string]: any} { return {'sampleSize': this._sampleSize}; } | ||||
| 
 | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[] { | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[]|null { | ||||
|     if (completeSample.length >= this._sampleSize) { | ||||
|       return completeSample.slice(completeSample.length - this._sampleSize, completeSample.length); | ||||
|     } else { | ||||
|  | ||||
| @ -43,7 +43,7 @@ export abstract class WebDriverExtension { | ||||
|       { | ||||
|         provide: WebDriverExtension, | ||||
|         useFactory: (children: WebDriverExtension[], capabilities: {[key: string]: any}) => { | ||||
|           let delegate: WebDriverExtension; | ||||
|           let delegate: WebDriverExtension = undefined !; | ||||
|           children.forEach(extension => { | ||||
|             if (extension.supports(capabilities)) { | ||||
|               delegate = extension; | ||||
| @ -64,7 +64,7 @@ export abstract class WebDriverExtension { | ||||
| 
 | ||||
|   timeBegin(name: string): Promise<any> { throw new Error('NYI'); } | ||||
| 
 | ||||
|   timeEnd(name: string, restartName: string): Promise<any> { throw new Error('NYI'); } | ||||
|   timeEnd(name: string, restartName: string|null): Promise<any> { throw new Error('NYI'); } | ||||
| 
 | ||||
|   /** | ||||
|    * Format: | ||||
|  | ||||
| @ -51,7 +51,7 @@ export class ChromeDriverExtension extends WebDriverExtension { | ||||
|     return this._driver.executeScript(`console.time('${name}');`); | ||||
|   } | ||||
| 
 | ||||
|   timeEnd(name: string, restartName: string = null): Promise<any> { | ||||
|   timeEnd(name: string, restartName: string|null = null): Promise<any> { | ||||
|     let script = `console.timeEnd('${name}');`; | ||||
|     if (restartName) { | ||||
|       script += `console.time('${restartName}');`; | ||||
| @ -82,14 +82,14 @@ export class ChromeDriverExtension extends WebDriverExtension { | ||||
|   } | ||||
| 
 | ||||
|   private _convertPerfRecordsToEvents( | ||||
|       chromeEvents: Array<{[key: string]: any}>, normalizedEvents: PerfLogEvent[] = null) { | ||||
|       chromeEvents: Array<{[key: string]: any}>, normalizedEvents: PerfLogEvent[]|null = null) { | ||||
|     if (!normalizedEvents) { | ||||
|       normalizedEvents = []; | ||||
|     } | ||||
|     chromeEvents.forEach((event) => { | ||||
|       const categories = this._parseCategories(event['cat']); | ||||
|       const normalizedEvent = this._convertEvent(event, categories); | ||||
|       if (normalizedEvent != null) normalizedEvents.push(normalizedEvent); | ||||
|       if (normalizedEvent != null) normalizedEvents !.push(normalizedEvent); | ||||
|     }); | ||||
|     return normalizedEvents; | ||||
|   } | ||||
| @ -167,7 +167,7 @@ export class ChromeDriverExtension extends WebDriverExtension { | ||||
| 
 | ||||
|   private _isEvent( | ||||
|       eventCategories: string[], eventName: string, expectedCategories: string[], | ||||
|       expectedName: string = null): boolean { | ||||
|       expectedName: string|null = null): boolean { | ||||
|     const hasCategories = expectedCategories.reduce( | ||||
|         (value, cat) => value && eventCategories.indexOf(cat) !== -1, true); | ||||
|     return !expectedName ? hasCategories : hasCategories && eventName === expectedName; | ||||
|  | ||||
| @ -32,7 +32,7 @@ export class FirefoxDriverExtension extends WebDriverExtension { | ||||
|     return this._driver.executeScript('window.markStart("' + name + '");'); | ||||
|   } | ||||
| 
 | ||||
|   timeEnd(name: string, restartName: string = null): Promise<any> { | ||||
|   timeEnd(name: string, restartName: string|null = null): Promise<any> { | ||||
|     let script = 'window.markEnd("' + name + '");'; | ||||
|     if (restartName != null) { | ||||
|       script += 'window.markStart("' + restartName + '");'; | ||||
|  | ||||
| @ -23,7 +23,7 @@ export class IOsDriverExtension extends WebDriverExtension { | ||||
|     return this._driver.executeScript(`console.time('${name}');`); | ||||
|   } | ||||
| 
 | ||||
|   timeEnd(name: string, restartName: string = null): Promise<any> { | ||||
|   timeEnd(name: string, restartName: string|null = null): Promise<any> { | ||||
|     let script = `console.timeEnd('${name}');`; | ||||
|     if (restartName != null) { | ||||
|       script += `console.time('${restartName}');`; | ||||
| @ -50,28 +50,28 @@ export class IOsDriverExtension extends WebDriverExtension { | ||||
|   } | ||||
| 
 | ||||
|   /** @internal */ | ||||
|   private _convertPerfRecordsToEvents(records: any[], events: PerfLogEvent[] = null) { | ||||
|   private _convertPerfRecordsToEvents(records: any[], events: PerfLogEvent[]|null = null) { | ||||
|     if (!events) { | ||||
|       events = []; | ||||
|     } | ||||
|     records.forEach((record) => { | ||||
|       let endEvent: PerfLogEvent = null; | ||||
|       let endEvent: PerfLogEvent|null = null; | ||||
|       const type = record['type']; | ||||
|       const data = record['data']; | ||||
|       const startTime = record['startTime']; | ||||
|       const endTime = record['endTime']; | ||||
| 
 | ||||
|       if (type === 'FunctionCall' && (data == null || data['scriptName'] !== 'InjectedScript')) { | ||||
|         events.push(createStartEvent('script', startTime)); | ||||
|         events !.push(createStartEvent('script', startTime)); | ||||
|         endEvent = createEndEvent('script', endTime); | ||||
|       } else if (type === 'Time') { | ||||
|         events.push(createMarkStartEvent(data['message'], startTime)); | ||||
|         events !.push(createMarkStartEvent(data['message'], startTime)); | ||||
|       } else if (type === 'TimeEnd') { | ||||
|         events.push(createMarkEndEvent(data['message'], startTime)); | ||||
|         events !.push(createMarkEndEvent(data['message'], startTime)); | ||||
|       } else if ( | ||||
|           type === 'RecalculateStyles' || type === 'Layout' || type === 'UpdateLayerTree' || | ||||
|           type === 'Paint' || type === 'Rasterize' || type === 'CompositeLayers') { | ||||
|         events.push(createStartEvent('render', startTime)); | ||||
|         events !.push(createStartEvent('render', startTime)); | ||||
|         endEvent = createEndEvent('render', endTime); | ||||
|       } | ||||
|       // Note: ios used to support GCEvent up until iOS 6 :-(
 | ||||
| @ -79,7 +79,7 @@ export class IOsDriverExtension extends WebDriverExtension { | ||||
|         this._convertPerfRecordsToEvents(record['children'], events); | ||||
|       } | ||||
|       if (endEvent != null) { | ||||
|         events.push(endEvent); | ||||
|         events !.push(endEvent); | ||||
|       } | ||||
|     }); | ||||
|     return events; | ||||
|  | ||||
| @ -80,7 +80,7 @@ export function main() { | ||||
|           sortedKeys(createMetric([[]], new PerfLogFeatures({render: true, gc: false})).describe())) | ||||
|           .toEqual(['pureScriptTime', 'renderTime', 'scriptTime']); | ||||
| 
 | ||||
|       expect(sortedKeys(createMetric([[]], null).describe())).toEqual([ | ||||
|       expect(sortedKeys(createMetric([[]], null !).describe())).toEqual([ | ||||
|         'gcAmount', 'gcTime', 'majorGcTime', 'pureScriptTime', 'renderTime', 'scriptTime' | ||||
|       ]); | ||||
| 
 | ||||
| @ -102,7 +102,7 @@ export function main() { | ||||
| 
 | ||||
|     it('should describe itself based on micro metrics', () => { | ||||
|       const description = | ||||
|           createMetric([[]], null, {microMetrics: {'myMicroMetric': 'someDesc'}}).describe(); | ||||
|           createMetric([[]], null !, {microMetrics: {'myMicroMetric': 'someDesc'}}).describe(); | ||||
|       expect(description['myMicroMetric']).toEqual('someDesc'); | ||||
|     }); | ||||
| 
 | ||||
| @ -130,7 +130,7 @@ export function main() { | ||||
| 
 | ||||
|       it('should not force gc and mark the timeline', | ||||
|          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||
|            const metric = createMetric([[]], null); | ||||
|            const metric = createMetric([[]], null !); | ||||
|            metric.beginMeasure().then((_) => { | ||||
|              expect(commandLog).toEqual([['timeBegin', 'benchpress0']]); | ||||
| 
 | ||||
| @ -140,7 +140,7 @@ export function main() { | ||||
| 
 | ||||
|       it('should force gc and mark the timeline', | ||||
|          inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||
|            const metric = createMetric([[]], null, {forceGc: true}); | ||||
|            const metric = createMetric([[]], null !, {forceGc: true}); | ||||
|            metric.beginMeasure().then((_) => { | ||||
|              expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]); | ||||
| 
 | ||||
| @ -158,7 +158,7 @@ export function main() { | ||||
|              eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4), | ||||
|              eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10) | ||||
|            ]]; | ||||
|            const metric = createMetric(events, null); | ||||
|            const metric = createMetric(events, null !); | ||||
|            metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => { | ||||
|              expect(commandLog).toEqual([ | ||||
|                ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog' | ||||
| @ -177,7 +177,7 @@ export function main() { | ||||
|              eventFactory.start('script', 8), eventFactory.end('script', 9), | ||||
|              eventFactory.markEnd('benchpress0', 10) | ||||
|            ]]; | ||||
|            const metric = createMetric(events, null); | ||||
|            const metric = createMetric(events, null !); | ||||
|            metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => { | ||||
|              expect(data['scriptTime']).toBe(1); | ||||
| 
 | ||||
| @ -194,7 +194,7 @@ export function main() { | ||||
|              ], | ||||
|              [eventFactory.markEnd('benchpress1', 3)] | ||||
|            ]; | ||||
|            const metric = createMetric(events, null); | ||||
|            const metric = createMetric(events, null !); | ||||
|            metric.beginMeasure() | ||||
|                .then((_) => metric.endMeasure(true)) | ||||
|                .then((_) => metric.endMeasure(true)) | ||||
| @ -218,7 +218,7 @@ export function main() { | ||||
|                eventFactory.markEnd('benchpress0', 10) | ||||
|              ] | ||||
|            ]; | ||||
|            const metric = createMetric(events, null); | ||||
|            const metric = createMetric(events, null !); | ||||
|            metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => { | ||||
|              expect(commandLog).toEqual([ | ||||
|                ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog', | ||||
| @ -243,7 +243,7 @@ export function main() { | ||||
|                eventFactory.markEnd('benchpress1', 6) | ||||
|              ] | ||||
|            ]; | ||||
|            const metric = createMetric(events, null); | ||||
|            const metric = createMetric(events, null !); | ||||
|            metric.beginMeasure() | ||||
|                .then((_) => metric.endMeasure(true)) | ||||
|                .then((data) => { | ||||
| @ -275,7 +275,7 @@ export function main() { | ||||
|         }); | ||||
| 
 | ||||
|         it('should measure forced gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||
|              const metric = createMetric(events, null, {forceGc: true}); | ||||
|              const metric = createMetric(events, null !, {forceGc: true}); | ||||
|              metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => { | ||||
|                expect(commandLog).toEqual([ | ||||
|                  ['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'], | ||||
| @ -290,7 +290,7 @@ export function main() { | ||||
| 
 | ||||
|         it('should restart after the forced gc if needed', | ||||
|            inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||
|              const metric = createMetric(events, null, {forceGc: true}); | ||||
|              const metric = createMetric(events, null !, {forceGc: true}); | ||||
|              metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => { | ||||
|                expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']); | ||||
| 
 | ||||
| @ -312,7 +312,7 @@ export function main() { | ||||
|       } = {}) { | ||||
|         events.unshift(eventFactory.markStart('benchpress0', 0)); | ||||
|         events.push(eventFactory.markEnd('benchpress0', 10)); | ||||
|         const metric = createMetric([events], null, { | ||||
|         const metric = createMetric([events], null !, { | ||||
|           microMetrics: microMetrics, | ||||
|           captureFrames: captureFrames, | ||||
|           receivedData: receivedData, | ||||
| @ -510,7 +510,7 @@ export function main() { | ||||
|                  otherProcessEventFactory.end('script', 17, null), | ||||
|                  eventFactory.markEnd('benchpress0', 20) | ||||
|                ]], | ||||
|                null); | ||||
|                null !); | ||||
|            metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => { | ||||
|              expect(data['scriptTime']).toBe(5); | ||||
|              async.done(); | ||||
| @ -674,7 +674,7 @@ class MockDriverExtension extends WebDriverExtension { | ||||
|     return Promise.resolve(null); | ||||
|   } | ||||
| 
 | ||||
|   timeEnd(name: string, restartName: string): Promise<any> { | ||||
|   timeEnd(name: string, restartName: string|null): Promise<any> { | ||||
|     this._commandLog.push(['timeEnd', name, restartName]); | ||||
|     return Promise.resolve(null); | ||||
|   } | ||||
|  | ||||
| @ -33,7 +33,7 @@ export function main() { | ||||
|       const providers: Provider[] = [ | ||||
|         ConsoleReporter.PROVIDERS, { | ||||
|           provide: SampleDescription, | ||||
|           useValue: new SampleDescription(sampleId, descriptions, metrics) | ||||
|           useValue: new SampleDescription(sampleId, descriptions, metrics !) | ||||
|         }, | ||||
|         {provide: ConsoleReporter.PRINT, useValue: (line: string) => log.push(line)} | ||||
|       ]; | ||||
|  | ||||
| @ -15,7 +15,7 @@ export function main() { | ||||
|     let injector: ReflectiveInjector; | ||||
|     let runner: Runner; | ||||
| 
 | ||||
|     function createRunner(defaultProviders: any[] = null): Runner { | ||||
|     function createRunner(defaultProviders?: any[]): Runner { | ||||
|       if (!defaultProviders) { | ||||
|         defaultProviders = []; | ||||
|       } | ||||
| @ -121,7 +121,7 @@ export function main() { | ||||
| 
 | ||||
| class MockWebDriverAdapter extends WebDriverAdapter { | ||||
|   executeScript(script: string): Promise<string> { return Promise.resolve('someUserAgent'); } | ||||
|   capabilities(): Promise<Map<string, any>> { return null; } | ||||
|   capabilities(): Promise<Map<string, any>> { return null !; } | ||||
| } | ||||
| 
 | ||||
| class MockValidator extends Validator { | ||||
| @ -135,6 +135,6 @@ class MockMetric extends Metric { | ||||
| } | ||||
| 
 | ||||
| class MockSampler extends Sampler { | ||||
|   constructor() { super(null, null, null, null, null, null, null); } | ||||
|   constructor() { super(null !, null !, null !, null !, null !, null !, null !); } | ||||
|   sample(): Promise<SampleState> { return Promise.resolve(new SampleState([], [])); } | ||||
| } | ||||
|  | ||||
| @ -147,7 +147,7 @@ export function main() { | ||||
|     it('should call the validator for every execution and store the valid sample', | ||||
|        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||
|          const log: any[] = []; | ||||
|          const validSample = [mv(null, null, {})]; | ||||
|          const validSample = [mv(null !, null !, {})]; | ||||
| 
 | ||||
|          createSampler({ | ||||
|            metric: createCountingMetric(), | ||||
| @ -174,7 +174,7 @@ export function main() { | ||||
|     it('should report the metric values', | ||||
|        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||
|          const log: any[] = []; | ||||
|          const validSample = [mv(null, null, {})]; | ||||
|          const validSample = [mv(null !, null !, {})]; | ||||
|          createSampler({ | ||||
|            validator: createCountingValidator(2, validSample), | ||||
|            metric: createCountingMetric(), | ||||
| @ -206,8 +206,7 @@ function mv(runIndex: number, time: number, values: {[key: string]: number}) { | ||||
|   return new MeasureValues(runIndex, new Date(time), values); | ||||
| } | ||||
| 
 | ||||
| function createCountingValidator( | ||||
|     count: number, validSample: MeasureValues[] = null, log: any[] = []) { | ||||
| function createCountingValidator(count: number, validSample?: MeasureValues[], log: any[] = []) { | ||||
|   return new MockValidator(log, (completeSample: MeasureValues[]) => { | ||||
|     count--; | ||||
|     if (count === 0) { | ||||
| @ -224,7 +223,7 @@ function createCountingMetric(log: any[] = []) { | ||||
| } | ||||
| 
 | ||||
| class MockDriverAdapter extends WebDriverAdapter { | ||||
|   constructor(private _log: any[] = [], private _waitFor: Function = null) { super(); } | ||||
|   constructor(private _log: any[] = [], private _waitFor: Function|null = null) { super(); } | ||||
|   waitFor(callback: Function): Promise<any> { | ||||
|     if (this._waitFor != null) { | ||||
|       return this._waitFor(callback); | ||||
| @ -236,7 +235,7 @@ class MockDriverAdapter extends WebDriverAdapter { | ||||
| 
 | ||||
| 
 | ||||
| class MockValidator extends Validator { | ||||
|   constructor(private _log: any[] = [], private _validate: Function = null) { super(); } | ||||
|   constructor(private _log: any[] = [], private _validate: Function|null = null) { super(); } | ||||
|   validate(completeSample: MeasureValues[]): MeasureValues[] { | ||||
|     const stableSample = this._validate != null ? this._validate(completeSample) : completeSample; | ||||
|     this._log.push(['validate', completeSample, stableSample]); | ||||
| @ -245,7 +244,7 @@ class MockValidator extends Validator { | ||||
| } | ||||
| 
 | ||||
| class MockMetric extends Metric { | ||||
|   constructor(private _log: any[] = [], private _endMeasure: Function = null) { super(); } | ||||
|   constructor(private _log: any[] = [], private _endMeasure: Function|null = null) { super(); } | ||||
|   beginMeasure() { | ||||
|     this._log.push(['beginMeasure']); | ||||
|     return Promise.resolve(null); | ||||
|  | ||||
| @ -32,7 +32,7 @@ export function main() { | ||||
|     const normEvents = new TraceEventFactory('timeline', 'pid0'); | ||||
| 
 | ||||
|     function createExtension( | ||||
|         perfRecords: any[] = null, userAgent: string = null, | ||||
|         perfRecords: any[] | null = null, userAgent: string | null = null, | ||||
|         messageMethod = 'Tracing.dataCollected'): WebDriverExtension { | ||||
|       if (!perfRecords) { | ||||
|         perfRecords = []; | ||||
| @ -392,7 +392,7 @@ class MockDriverAdapter extends WebDriverAdapter { | ||||
|     return Promise.resolve(null); | ||||
|   } | ||||
| 
 | ||||
|   logs(type: string) { | ||||
|   logs(type: string): Promise<any[]> { | ||||
|     this._log.push(['logs', type]); | ||||
|     if (type === 'performance') { | ||||
|       return Promise.resolve(this._events.map( | ||||
| @ -401,7 +401,7 @@ class MockDriverAdapter extends WebDriverAdapter { | ||||
|                 {'message': {'method': this._messageMethod, 'params': event}}, null, 2) | ||||
|           }))); | ||||
|     } else { | ||||
|       return null; | ||||
|       return null !; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -18,7 +18,7 @@ export function main() { | ||||
| 
 | ||||
|     const normEvents = new TraceEventFactory('timeline', 'pid0'); | ||||
| 
 | ||||
|     function createExtension(perfRecords: any[] = null): WebDriverExtension { | ||||
|     function createExtension(perfRecords: any[] | null = null): WebDriverExtension { | ||||
|       if (!perfRecords) { | ||||
|         perfRecords = []; | ||||
|       } | ||||
| @ -154,7 +154,8 @@ function timeEndRecord(name: string, time: number) { | ||||
|   return {'type': 'TimeEnd', 'startTime': time, 'data': {'message': name}}; | ||||
| } | ||||
| 
 | ||||
| function durationRecord(type: string, startTime: number, endTime: number, children: any[] = null) { | ||||
| function durationRecord( | ||||
|     type: string, startTime: number, endTime: number, children: any[] | null = null) { | ||||
|   if (!children) { | ||||
|     children = []; | ||||
|   } | ||||
| @ -178,7 +179,7 @@ class MockDriverAdapter extends WebDriverAdapter { | ||||
|     return Promise.resolve(null); | ||||
|   } | ||||
| 
 | ||||
|   logs(type: string) { | ||||
|   logs(type: string): Promise<any[]> { | ||||
|     this._log.push(['logs', type]); | ||||
|     if (type === 'performance') { | ||||
|       return Promise.resolve(this._perfRecords.map(function(record) { | ||||
| @ -189,7 +190,7 @@ class MockDriverAdapter extends WebDriverAdapter { | ||||
|         }; | ||||
|       })); | ||||
|     } else { | ||||
|       return null; | ||||
|       return null !; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user