2016-08-03 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
2016-06-02 20:30:40 -04:00
|
|
|
import {Metric, MultiMetric, ReflectiveInjector} from 'benchpress/common';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
2015-10-06 22:05:09 -04:00
|
|
|
function createMetric(ids: any[]) {
|
2016-08-03 18:00:07 -04:00
|
|
|
var m = ReflectiveInjector
|
|
|
|
.resolveAndCreate([
|
|
|
|
ids.map(id => { return {provide: id, useValue: new MockMetric(id)}; }),
|
|
|
|
MultiMetric.createBindings(ids)
|
|
|
|
])
|
2015-06-26 18:59:18 -04:00
|
|
|
.get(MultiMetric);
|
2016-04-28 20:50:03 -04:00
|
|
|
return Promise.resolve(m);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('multi metric', () => {
|
|
|
|
it('should merge descriptions', inject([AsyncTestCompleter], (async) => {
|
2016-08-03 18:00:07 -04:00
|
|
|
createMetric(['m1', 'm2']).then((m) => {
|
|
|
|
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should merge all beginMeasure calls', inject([AsyncTestCompleter], (async) => {
|
2016-08-03 18:00:07 -04:00
|
|
|
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
|
|
|
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
[false, true].forEach((restartFlag) => {
|
|
|
|
it(`should merge all endMeasure calls for restart=${restartFlag}`,
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
2016-08-03 18:00:07 -04:00
|
|
|
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
|
|
|
expect(values).toEqual(
|
|
|
|
{'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockMetric extends Metric {
|
2016-08-03 18:00:07 -04:00
|
|
|
/** @internal */
|
|
|
|
private _id: string;
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
constructor(id) {
|
|
|
|
super();
|
|
|
|
this._id = id;
|
|
|
|
}
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
beginMeasure(): Promise<string> { return Promise.resolve(`${this._id}_beginMeasure`); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
endMeasure(restart: boolean): Promise<{[key: string]: any}> {
|
2015-05-27 17:57:54 -04:00
|
|
|
var result = {};
|
2015-06-12 10:50:45 -04:00
|
|
|
result[this._id] = {'restart': restart};
|
2016-04-28 20:50:03 -04:00
|
|
|
return Promise.resolve(result);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
describe(): {[key: string]: string} {
|
2015-10-02 20:33:21 -04:00
|
|
|
var result: {[key: string]: string} = {};
|
2015-05-27 17:57:54 -04:00
|
|
|
result[this._id] = 'describe';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|