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
|
|
|
|
*/
|
|
|
|
|
2016-08-24 16:39:44 -04:00
|
|
|
import {Provider, ReflectiveInjector} from '@angular/core';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
import {Options} from './common_options';
|
2016-09-27 20:12:25 -04:00
|
|
|
import {isPresent} from './facade/lang';
|
2016-08-03 18:00:07 -04:00
|
|
|
import {Metric} from './metric';
|
|
|
|
import {MultiMetric} from './metric/multi_metric';
|
|
|
|
import {PerflogMetric} from './metric/perflog_metric';
|
|
|
|
import {UserMetric} from './metric/user_metric';
|
|
|
|
import {Reporter} from './reporter';
|
2015-05-27 17:57:54 -04:00
|
|
|
import {ConsoleReporter} from './reporter/console_reporter';
|
|
|
|
import {MultiReporter} from './reporter/multi_reporter';
|
2016-08-03 18:00:07 -04:00
|
|
|
import {SampleDescription} from './sample_description';
|
|
|
|
import {SampleState, Sampler} from './sampler';
|
|
|
|
import {Validator} from './validator';
|
2015-05-27 17:57:54 -04:00
|
|
|
import {RegressionSlopeValidator} from './validator/regression_slope_validator';
|
|
|
|
import {SizeValidator} from './validator/size_validator';
|
2016-08-03 18:00:07 -04:00
|
|
|
import {WebDriverAdapter} from './web_driver_adapter';
|
|
|
|
import {WebDriverExtension} from './web_driver_extension';
|
2015-05-27 17:57:54 -04:00
|
|
|
import {ChromeDriverExtension} from './webdriver/chrome_driver_extension';
|
2015-06-08 16:51:10 -04:00
|
|
|
import {FirefoxDriverExtension} from './webdriver/firefox_driver_extension';
|
2015-05-27 17:57:54 -04:00
|
|
|
import {IOsDriverExtension} from './webdriver/ios_driver_extension';
|
2016-08-03 18:00:07 -04:00
|
|
|
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
|
2015-05-27 17:57:54 -04:00
|
|
|
/**
|
|
|
|
* The Runner is the main entry point for executing a sample run.
|
|
|
|
* It provides defaults, creates the injector and calls the sampler.
|
|
|
|
*/
|
|
|
|
export class Runner {
|
2016-08-26 19:34:08 -04:00
|
|
|
constructor(private _defaultProviders: Provider[] = []) {}
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
sample({id, execute, prepare, microMetrics, providers, userMetrics}: {
|
|
|
|
id: string,
|
2016-08-26 19:34:08 -04:00
|
|
|
execute?: Function,
|
|
|
|
prepare?: Function,
|
|
|
|
microMetrics?: {[key: string]: string},
|
|
|
|
providers?: Provider[],
|
|
|
|
userMetrics?: {[key: string]: string}
|
2016-08-03 18:00:07 -04:00
|
|
|
}): Promise<SampleState> {
|
2016-08-26 19:34:08 -04:00
|
|
|
var sampleProviders: Provider[] = [
|
2016-08-03 18:00:07 -04:00
|
|
|
_DEFAULT_PROVIDERS, this._defaultProviders, {provide: Options.SAMPLE_ID, useValue: id},
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: Options.EXECUTE, useValue: execute}
|
2015-05-27 17:57:54 -04:00
|
|
|
];
|
|
|
|
if (isPresent(prepare)) {
|
2016-06-02 20:30:40 -04:00
|
|
|
sampleProviders.push({provide: Options.PREPARE, useValue: prepare});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
if (isPresent(microMetrics)) {
|
2016-06-02 20:30:40 -04:00
|
|
|
sampleProviders.push({provide: Options.MICRO_METRICS, useValue: microMetrics});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2016-04-20 20:01:51 -04:00
|
|
|
if (isPresent(userMetrics)) {
|
|
|
|
sampleProviders.push({provide: Options.USER_METRICS, useValue: userMetrics});
|
|
|
|
}
|
2016-03-21 06:57:17 -04:00
|
|
|
if (isPresent(providers)) {
|
|
|
|
sampleProviders.push(providers);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2015-06-26 18:59:18 -04:00
|
|
|
|
2016-03-21 06:57:17 -04:00
|
|
|
var inj = ReflectiveInjector.resolveAndCreate(sampleProviders);
|
2016-09-09 13:37:47 -04:00
|
|
|
var adapter: WebDriverAdapter = inj.get(WebDriverAdapter);
|
2015-06-26 18:59:18 -04:00
|
|
|
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise
|
2015-06-26 18:59:18 -04:00
|
|
|
.all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
|
|
|
|
.then((args) => {
|
|
|
|
var capabilities = args[0];
|
|
|
|
var userAgent = args[1];
|
|
|
|
|
|
|
|
// This might still create instances twice. We are creating a new injector with all the
|
2015-10-11 01:11:13 -04:00
|
|
|
// providers.
|
2015-06-26 18:59:18 -04:00
|
|
|
// Only WebDriverAdapter is reused.
|
|
|
|
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
|
|
|
|
// injectors are handled better.
|
2016-04-14 15:35:24 -04:00
|
|
|
var injector = ReflectiveInjector.resolveAndCreate([
|
2016-08-03 18:00:07 -04:00
|
|
|
sampleProviders, {provide: Options.CAPABILITIES, useValue: capabilities},
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: Options.USER_AGENT, useValue: userAgent},
|
|
|
|
{provide: WebDriverAdapter, useValue: adapter}
|
2015-06-26 18:59:18 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
var sampler = injector.get(Sampler);
|
|
|
|
return sampler.sample();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
var _DEFAULT_PROVIDERS = [
|
|
|
|
Options.DEFAULT_PROVIDERS,
|
2016-03-21 06:57:17 -04:00
|
|
|
Sampler.PROVIDERS,
|
|
|
|
ConsoleReporter.PROVIDERS,
|
|
|
|
RegressionSlopeValidator.PROVIDERS,
|
|
|
|
SizeValidator.PROVIDERS,
|
|
|
|
ChromeDriverExtension.PROVIDERS,
|
|
|
|
FirefoxDriverExtension.PROVIDERS,
|
|
|
|
IOsDriverExtension.PROVIDERS,
|
|
|
|
PerflogMetric.PROVIDERS,
|
2016-08-03 15:32:26 -04:00
|
|
|
UserMetric.PROVIDERS,
|
2016-03-21 06:57:17 -04:00
|
|
|
SampleDescription.PROVIDERS,
|
2016-08-26 19:34:08 -04:00
|
|
|
MultiReporter.provideWith([ConsoleReporter]),
|
|
|
|
MultiMetric.provideWith([PerflogMetric, UserMetric]),
|
|
|
|
{provide: Reporter, useExisting: MultiReporter},
|
|
|
|
{provide: Validator, useExisting: RegressionSlopeValidator},
|
|
|
|
WebDriverExtension.provideFirstSupported(
|
|
|
|
[ChromeDriverExtension, FirefoxDriverExtension, IOsDriverExtension]),
|
|
|
|
{provide: Metric, useExisting: MultiMetric},
|
2015-05-27 17:57:54 -04:00
|
|
|
];
|