2015-05-27 17:57:54 -04:00
|
|
|
import {
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
|
|
|
} from 'angular2/test_lib';
|
|
|
|
|
2015-08-28 14:29:19 -04:00
|
|
|
import {ListWrapper, StringMap} from 'angular2/src/core/facade/collection';
|
2015-08-20 17:28:25 -04:00
|
|
|
import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {Metric, MultiMetric, bind, Injector} from 'benchpress/common';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
function createMetric(ids) {
|
2015-06-26 18:59:18 -04:00
|
|
|
var m = Injector.resolveAndCreate([
|
|
|
|
ListWrapper.map(ids, (id) => bind(id).toValue(new MockMetric(id))),
|
|
|
|
MultiMetric.createBindings(ids)
|
|
|
|
])
|
|
|
|
.get(MultiMetric);
|
|
|
|
return PromiseWrapper.resolve(m);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('multi metric', () => {
|
|
|
|
it('should merge descriptions', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createMetric(['m1', 'm2'])
|
|
|
|
.then((m) => {
|
|
|
|
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should merge all beginMeasure calls', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createMetric(['m1', 'm2'])
|
|
|
|
.then((m) => m.beginMeasure())
|
|
|
|
.then((values) => {
|
|
|
|
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
[false, true].forEach((restartFlag) => {
|
|
|
|
it(`should merge all endMeasure calls for restart=${restartFlag}`,
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
createMetric(['m1', 'm2'])
|
|
|
|
.then((m) => m.endMeasure(restartFlag))
|
|
|
|
.then((values) => {
|
|
|
|
expect(values)
|
|
|
|
.toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockMetric extends Metric {
|
|
|
|
_id: string;
|
|
|
|
|
|
|
|
constructor(id) {
|
|
|
|
super();
|
|
|
|
this._id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
beginMeasure(): Promise<string> { return PromiseWrapper.resolve(`${this._id}_beginMeasure`); }
|
|
|
|
|
|
|
|
endMeasure(restart: boolean): Promise<StringMap<string, any>> {
|
|
|
|
var result = {};
|
2015-06-12 10:50:45 -04:00
|
|
|
result[this._id] = {'restart': restart};
|
2015-05-27 17:57:54 -04:00
|
|
|
return PromiseWrapper.resolve(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe(): StringMap<string, string> {
|
|
|
|
var result = {};
|
|
|
|
result[this._id] = 'describe';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|