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-04-20 20:01:51 -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
|
|
|
import {Injector, StaticProvider} from '@angular/core';
|
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
|
|
|
|
2016-09-27 20:12:25 -04:00
|
|
|
import {Options, PerfLogEvent, PerfLogFeatures, UserMetric, WebDriverAdapter} from '../../index';
|
2016-04-20 20:01:51 -04:00
|
|
|
|
2017-12-17 18:10:54 -05:00
|
|
|
(function() {
|
2016-11-12 08:08:58 -05:00
|
|
|
let wdAdapter: MockDriverAdapter;
|
2016-04-20 20:01:51 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
function createMetric(
|
2016-08-26 19:34:08 -04:00
|
|
|
perfLogs: PerfLogEvent[], perfLogFeatures: PerfLogFeatures,
|
2016-08-03 18:00:07 -04:00
|
|
|
{userMetrics}: {userMetrics?: {[key: string]: string}} = {}): UserMetric {
|
2016-09-30 12:26:53 -04:00
|
|
|
if (!perfLogFeatures) {
|
2016-04-20 20:01:51 -04:00
|
|
|
perfLogFeatures =
|
|
|
|
new PerfLogFeatures({render: true, gc: true, frameCapture: true, userTiming: true});
|
|
|
|
}
|
2016-09-30 12:26:53 -04:00
|
|
|
if (!userMetrics) {
|
2016-09-19 20:15:57 -04:00
|
|
|
userMetrics = {};
|
2016-04-20 20:01:51 -04:00
|
|
|
}
|
|
|
|
wdAdapter = new MockDriverAdapter();
|
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 providers: StaticProvider[] = [
|
2016-08-03 18:00:07 -04:00
|
|
|
Options.DEFAULT_PROVIDERS, UserMetric.PROVIDERS,
|
2016-08-15 22:37:42 -04:00
|
|
|
{provide: Options.USER_METRICS, useValue: userMetrics},
|
|
|
|
{provide: WebDriverAdapter, useValue: wdAdapter}
|
2016-04-20 20:01:51 -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
|
|
|
return Injector.create(providers).get(UserMetric);
|
2016-04-20 20:01:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('user metric', () => {
|
|
|
|
|
|
|
|
it('should describe itself based on userMetrics', () => {
|
2016-08-03 18:00:07 -04:00
|
|
|
expect(createMetric([[]], new PerfLogFeatures(), {
|
|
|
|
userMetrics: {'loadTime': 'time to load'}
|
|
|
|
}).describe())
|
2016-04-20 20:01:51 -04:00
|
|
|
.toEqual({'loadTime': 'time to load'});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('endMeasure', () => {
|
|
|
|
it('should stop measuring when all properties have numeric values',
|
2016-08-26 19:34:08 -04:00
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const metric = createMetric(
|
2016-04-20 20:01:51 -04:00
|
|
|
[[]], new PerfLogFeatures(),
|
|
|
|
{userMetrics: {'loadTime': 'time to load', 'content': 'time to see content'}});
|
|
|
|
metric.beginMeasure()
|
|
|
|
.then((_) => metric.endMeasure(true))
|
|
|
|
.then((values: {[key: string]: string}) => {
|
|
|
|
expect(values['loadTime']).toBe(25);
|
|
|
|
expect(values['content']).toBe(250);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
|
|
|
|
wdAdapter.data['loadTime'] = 25;
|
|
|
|
// Wait before setting 2nd property.
|
2016-08-02 18:53:34 -04:00
|
|
|
setTimeout(() => { wdAdapter.data['content'] = 250; }, 50);
|
2016-04-20 20:01:51 -04:00
|
|
|
|
|
|
|
}), 600);
|
|
|
|
});
|
|
|
|
});
|
2017-12-16 17:42:55 -05:00
|
|
|
})();
|
2016-04-20 20:01:51 -04:00
|
|
|
|
|
|
|
class MockDriverAdapter extends WebDriverAdapter {
|
|
|
|
data: any = {};
|
|
|
|
|
|
|
|
executeScript(script: string): any {
|
|
|
|
// Just handles `return window.propName` ignores `delete window.propName`.
|
|
|
|
if (script.indexOf('return window.') == 0) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const metricName = script.substring('return window.'.length);
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise.resolve(this.data[metricName]);
|
2016-04-20 20:01:51 -04:00
|
|
|
} else if (script.indexOf('delete window.') == 0) {
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise.resolve(null);
|
2016-04-20 20:01:51 -04:00
|
|
|
} else {
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise.reject(`Unexpected syntax: ${script}`);
|
2016-04-20 20:01:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|