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
|
|
|
|
*/
|
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
import {Injector, StaticProvider} from '@angular/core';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
import {Options} from './common_options';
|
|
|
|
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 {
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
constructor(private _defaultProviders: StaticProvider[] = []) {}
|
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},
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
providers?: StaticProvider[],
|
2016-08-26 19:34:08 -04:00
|
|
|
userMetrics?: {[key: string]: string}
|
2016-08-03 18:00:07 -04:00
|
|
|
}): Promise<SampleState> {
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
const sampleProviders: StaticProvider[] = [
|
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
|
|
|
];
|
2017-03-02 12:37:01 -05:00
|
|
|
if (prepare != null) {
|
2016-06-02 20:30:40 -04:00
|
|
|
sampleProviders.push({provide: Options.PREPARE, useValue: prepare});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2017-03-02 12:37:01 -05:00
|
|
|
if (microMetrics != null) {
|
2016-06-02 20:30:40 -04:00
|
|
|
sampleProviders.push({provide: Options.MICRO_METRICS, useValue: microMetrics});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2017-03-02 12:37:01 -05:00
|
|
|
if (userMetrics != null) {
|
2016-04-20 20:01:51 -04:00
|
|
|
sampleProviders.push({provide: Options.USER_METRICS, useValue: userMetrics});
|
|
|
|
}
|
2017-03-02 12:37:01 -05:00
|
|
|
if (providers != null) {
|
2016-03-21 06:57:17 -04:00
|
|
|
sampleProviders.push(providers);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2015-06-26 18:59:18 -04:00
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
const inj = Injector.create(sampleProviders);
|
2016-11-12 08:08:58 -05:00
|
|
|
const 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) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const capabilities = args[0];
|
|
|
|
const userAgent = args[1];
|
2015-06-26 18:59:18 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-04-08 17:19:25 -04:00
|
|
|
// TODO(vsavkin): consider changing it when toAsyncFactory is added back or when child
|
2015-06-26 18:59:18 -04:00
|
|
|
// injectors are handled better.
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
const injector = Injector.create([
|
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
|
|
|
]);
|
|
|
|
|
2017-10-26 20:23:30 -04:00
|
|
|
// TODO: With TypeScript 2.5 injector.get does not infer correctly the
|
|
|
|
// return type. Remove 'any' and investigate the issue.
|
|
|
|
const sampler = injector.get(Sampler) as any;
|
2015-06-26 18:59:18 -04:00
|
|
|
return sampler.sample();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
const _DEFAULT_PROVIDERS = [
|
2015-10-11 01:11:13 -04:00
|
|
|
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
|
|
|
];
|