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';
|
|
|
|
import {isBlank} from '@angular/facade/src/lang';
|
|
|
|
import {Injector, Metric, Options, ReflectiveInjector, Runner, SampleDescription, SampleState, Sampler, Validator, WebDriverAdapter} from 'benchpress/common';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('runner', () => {
|
2016-04-14 15:35:24 -04:00
|
|
|
var injector: ReflectiveInjector;
|
2015-05-27 17:57:54 -04:00
|
|
|
var runner;
|
|
|
|
|
2016-02-19 14:49:31 -05:00
|
|
|
function createRunner(defaultBindings = null): Runner {
|
2015-05-27 17:57:54 -04:00
|
|
|
if (isBlank(defaultBindings)) {
|
|
|
|
defaultBindings = [];
|
|
|
|
}
|
|
|
|
runner = new Runner([
|
2016-08-03 18:00:07 -04:00
|
|
|
defaultBindings, {
|
2016-06-02 20:30:40 -04:00
|
|
|
provide: Sampler,
|
|
|
|
useFactory: (_injector) => {
|
|
|
|
injector = _injector;
|
|
|
|
return new MockSampler();
|
|
|
|
},
|
|
|
|
deps: [Injector]
|
|
|
|
},
|
2016-08-03 18:00:07 -04:00
|
|
|
{provide: Metric, useFactory: () => new MockMetric(), deps: []},
|
|
|
|
{provide: Validator, useFactory: () => new MockValidator(), deps: []},
|
|
|
|
{provide: WebDriverAdapter, useFactory: () => new MockWebDriverAdapter(), deps: []}
|
2015-05-27 17:57:54 -04:00
|
|
|
]);
|
|
|
|
return runner;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should set SampleDescription.id', inject([AsyncTestCompleter], (async) => {
|
|
|
|
createRunner()
|
|
|
|
.sample({id: 'someId'})
|
2015-06-26 18:59:18 -04:00
|
|
|
.then((_) => injector.get(SampleDescription))
|
2015-05-27 17:57:54 -04:00
|
|
|
.then((desc) => {
|
|
|
|
expect(desc.id).toBe('someId');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => {
|
2016-06-02 20:30:40 -04:00
|
|
|
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
2016-08-03 18:00:07 -04:00
|
|
|
.sample({
|
|
|
|
id: 'someId',
|
|
|
|
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: {'b': 2}}]
|
|
|
|
})
|
2015-06-26 18:59:18 -04:00
|
|
|
.then((_) => injector.get(SampleDescription))
|
2015-05-27 17:57:54 -04:00
|
|
|
.then((desc) => {
|
|
|
|
expect(desc.description)
|
|
|
|
.toEqual(
|
|
|
|
{'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should fill SampleDescription.metrics from the Metric',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
createRunner()
|
|
|
|
.sample({id: 'someId'})
|
2015-06-26 18:59:18 -04:00
|
|
|
.then((_) => injector.get(SampleDescription))
|
2015-05-27 17:57:54 -04:00
|
|
|
.then((desc) => {
|
|
|
|
|
|
|
|
expect(desc.metrics).toEqual({'m1': 'some metric'});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should bind Options.EXECUTE', inject([AsyncTestCompleter], (async) => {
|
|
|
|
var execute = () => {};
|
2016-08-03 18:00:07 -04:00
|
|
|
createRunner().sample({id: 'someId', execute: execute}).then((_) => {
|
|
|
|
expect(injector.get(Options.EXECUTE)).toEqual(execute);
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should bind Options.PREPARE', inject([AsyncTestCompleter], (async) => {
|
|
|
|
var prepare = () => {};
|
2016-08-03 18:00:07 -04:00
|
|
|
createRunner().sample({id: 'someId', prepare: prepare}).then((_) => {
|
|
|
|
expect(injector.get(Options.PREPARE)).toEqual(prepare);
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should bind Options.MICRO_METRICS', inject([AsyncTestCompleter], (async) => {
|
2016-08-03 18:00:07 -04:00
|
|
|
createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then((_) => {
|
|
|
|
expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should overwrite bindings per sample call', inject([AsyncTestCompleter], (async) => {
|
2016-06-02 20:30:40 -04:00
|
|
|
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
2015-05-27 17:57:54 -04:00
|
|
|
.sample({
|
|
|
|
id: 'someId',
|
2016-06-02 20:30:40 -04:00
|
|
|
providers: [{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 2}}]
|
2015-05-27 17:57:54 -04:00
|
|
|
})
|
2015-06-26 18:59:18 -04:00
|
|
|
.then((_) => injector.get(SampleDescription))
|
2015-05-27 17:57:54 -04:00
|
|
|
.then((desc) => {
|
|
|
|
|
2015-06-26 18:59:18 -04:00
|
|
|
expect(desc.description['a']).toBe(2);
|
2015-05-27 17:57:54 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockWebDriverAdapter extends WebDriverAdapter {
|
2016-08-02 18:53:34 -04:00
|
|
|
executeScript(script): Promise<string> { return Promise.resolve('someUserAgent'); }
|
2015-06-26 18:59:18 -04:00
|
|
|
capabilities() { return null; }
|
2015-05-27 17:57:54 -04: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(); }
|
2016-08-02 18:53:34 -04:00
|
|
|
sample(): Promise<SampleState> { return Promise.resolve(new SampleState([], [])); }
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|