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
|
|
|
|
*/
|
|
|
|
|
2017-03-02 15:12:46 -05:00
|
|
|
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
2016-08-26 19:34:08 -04:00
|
|
|
|
|
|
|
import {Injector, Metric, Options, ReflectiveInjector, Runner, SampleDescription, SampleState, Sampler, Validator, WebDriverAdapter} from '../index';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('runner', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
let injector: ReflectiveInjector;
|
|
|
|
let runner: Runner;
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2017-03-24 12:56:50 -04:00
|
|
|
function createRunner(defaultProviders?: any[]): Runner {
|
2016-09-30 12:26:53 -04:00
|
|
|
if (!defaultProviders) {
|
2016-08-26 19:34:08 -04:00
|
|
|
defaultProviders = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
runner = new Runner([
|
2016-08-26 19:34:08 -04:00
|
|
|
defaultProviders, {
|
2016-06-02 20:30:40 -04:00
|
|
|
provide: Sampler,
|
2016-08-26 19:34:08 -04:00
|
|
|
useFactory: (_injector: ReflectiveInjector) => {
|
2016-06-02 20:30:40 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should set SampleDescription.id',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2015-05-27 17:57:54 -04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should merge SampleDescription.description',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
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',
|
2016-08-26 19:34:08 -04:00
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2015-05-27 17:57:54 -04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should provide Options.EXECUTE',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const 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
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should provide Options.PREPARE',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const 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
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should provide Options.MICRO_METRICS',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
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
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should overwrite providers per sample call',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
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-26 19:34:08 -04:00
|
|
|
executeScript(script: string): Promise<string> { return Promise.resolve('someUserAgent'); }
|
2017-03-24 12:56:50 -04:00
|
|
|
capabilities(): Promise<Map<string, any>> { 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 {
|
2017-03-24 12:56:50 -04:00
|
|
|
constructor() { super(null !, null !, null !, null !, null !, null !, null !); }
|
2016-08-02 18:53:34 -04:00
|
|
|
sample(): Promise<SampleState> { return Promise.resolve(new SampleState([], [])); }
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|