diff --git a/packages/benchpress/src/webdriver/chrome_driver_extension.ts b/packages/benchpress/src/webdriver/chrome_driver_extension.ts index bd767bb874..3052c3db97 100644 --- a/packages/benchpress/src/webdriver/chrome_driver_extension.ts +++ b/packages/benchpress/src/webdriver/chrome_driver_extension.ts @@ -24,6 +24,7 @@ export class ChromeDriverExtension extends WebDriverExtension { static PROVIDERS = [ChromeDriverExtension]; private _majorChromeVersion: number; + private _firstRun = true; constructor(private _driver: WebDriverAdapter, @Inject(Options.USER_AGENT) userAgent: string) { super(); @@ -48,6 +49,12 @@ export class ChromeDriverExtension extends WebDriverExtension { gc() { return this._driver.executeScript('window.gc()'); } timeBegin(name: string): Promise { + if (this._firstRun) { + this._firstRun = false; + // Before the first run, read out the existing performance logs + // so that the chrome buffer does not fill up. + this._driver.logs('performance'); + } return this._driver.executeScript(`console.time('${name}');`); } diff --git a/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts b/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts index 5cde6cacad..f12d8a8bd6 100644 --- a/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts +++ b/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal'; +import {AsyncTestCompleter, describe, expect, iit, inject, it} from '@angular/core/testing/src/testing_internal'; import {ChromeDriverExtension, Options, ReflectiveInjector, WebDriverAdapter, WebDriverExtension} from '../../index'; import {TraceEventFactory} from '../trace_event_factory'; @@ -61,14 +61,29 @@ export function main() { }); })); - it('should mark the timeline via console.time()', + it('should clear the perf logs and mark the timeline via console.time() on the first call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - createExtension().timeBegin('someName').then((_) => { - expect(log).toEqual([['executeScript', `console.time('someName');`]]); + createExtension().timeBegin('someName').then(() => { + expect(log).toEqual( + [['logs', 'performance'], ['executeScript', `console.time('someName');`]]); async.done(); }); })); + it('should mark the timeline via console.time() on the second call', + inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + const ext = createExtension(); + ext.timeBegin('someName') + .then((_) => { + log.splice(0, log.length); + ext.timeBegin('someName'); + }) + .then(() => { + expect(log).toEqual([['executeScript', `console.time('someName');`]]); + async.done(); + }); + })); + it('should mark the timeline via console.timeEnd()', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { createExtension().timeEnd('someName', null).then((_) => {