2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
|
|
|
} from 'angular2/testing_internal';
|
|
|
|
import {
|
|
|
|
Runner,
|
|
|
|
Sampler,
|
|
|
|
SampleDescription,
|
|
|
|
Validator,
|
|
|
|
bind,
|
|
|
|
provide,
|
|
|
|
Injector,
|
|
|
|
Metric,
|
|
|
|
Options,
|
|
|
|
WebDriverAdapter,
|
|
|
|
SampleState
|
|
|
|
} from 'benchpress/common';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {isBlank} from 'angular2/src/facade/lang';
|
2016-02-08 16:24:09 -05:00
|
|
|
import {PromiseWrapper} from 'angular2/src/facade/async';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('runner', () => {
|
2015-06-11 21:50:41 -04:00
|
|
|
var injector: Injector;
|
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-04-12 12:40:37 -04:00
|
|
|
defaultBindings,
|
|
|
|
bind(Sampler).toFactory(
|
|
|
|
(_injector) => {
|
|
|
|
injector = _injector;
|
|
|
|
return new MockSampler();
|
|
|
|
},
|
|
|
|
[Injector]),
|
2015-05-27 17:57:54 -04:00
|
|
|
bind(Metric).toFactory(() => new MockMetric(), []),
|
|
|
|
bind(Validator).toFactory(() => new MockValidator(), []),
|
|
|
|
bind(WebDriverAdapter).toFactory(() => new MockWebDriverAdapter(), [])
|
|
|
|
]);
|
|
|
|
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) => {
|
|
|
|
createRunner([bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1})])
|
2015-06-03 16:42:57 -04:00
|
|
|
.sample({id: 'someId', bindings: [bind(Options.SAMPLE_DESCRIPTION).toValue({'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-04-12 12:40:37 -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-04-12 12:40:37 -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-04-12 12:40:37 -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) => {
|
|
|
|
createRunner([
|
2016-04-12 12:40:37 -04:00
|
|
|
bind(Options.DEFAULT_DESCRIPTION)
|
|
|
|
.toValue({'a': 1}),
|
2015-05-27 17:57:54 -04:00
|
|
|
])
|
|
|
|
.sample({
|
|
|
|
id: 'someId',
|
|
|
|
bindings: [
|
2016-04-12 12:40:37 -04:00
|
|
|
bind(Options.DEFAULT_DESCRIPTION)
|
|
|
|
.toValue({'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 {
|
|
|
|
executeScript(script): Promise<string> { return PromiseWrapper.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(); }
|
2015-07-07 23:03:00 -04:00
|
|
|
sample(): Promise<SampleState> { return PromiseWrapper.resolve(new SampleState([], [])); }
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|