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
|
|
|
|
*/
|
2015-05-27 17:57:54 -04:00
|
|
|
|
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
|
|
|
|
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, MeasureValues, MultiReporter, Reporter} from '../../index';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2017-12-17 18:10:54 -05:00
|
|
|
(function() {
|
2015-10-06 22:05:09 -04:00
|
|
|
function createReporters(ids: any[]) {
|
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 r = Injector
|
|
|
|
.create([
|
2016-11-12 08:08:58 -05:00
|
|
|
ids.map(id => ({provide: id, useValue: new MockReporter(id)})),
|
|
|
|
MultiReporter.provideWith(ids)
|
|
|
|
])
|
2017-11-15 11:43:35 -05:00
|
|
|
.get<MultiReporter>(MultiReporter);
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise.resolve(r);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('multi reporter', () => {
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should reportMeasureValues to all',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const mv = new MeasureValues(0, new Date(), {});
|
2016-08-03 18:00:07 -04:00
|
|
|
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const completeSample =
|
2016-10-02 17:12:14 -04:00
|
|
|
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
2016-11-12 08:08:58 -05:00
|
|
|
const validSample = [completeSample[1]];
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
createReporters(['m1', 'm2'])
|
|
|
|
.then((r) => r.reportSample(completeSample, validSample))
|
|
|
|
.then((values) => {
|
|
|
|
|
|
|
|
expect(values).toEqual([
|
|
|
|
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
|
|
|
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
|
|
|
]);
|
|
|
|
async.done();
|
2016-08-03 18:00:07 -04:00
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2017-12-16 17:42:55 -05:00
|
|
|
})();
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
class MockReporter extends Reporter {
|
|
|
|
constructor(private _id: string) { super(); }
|
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
reportMeasureValues(values: MeasureValues): Promise<{[key: string]: any}> {
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise.resolve({'id': this._id, 'values': values});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]):
|
|
|
|
Promise<{[key: string]: any}> {
|
2016-08-02 18:53:34 -04:00
|
|
|
return Promise.resolve(
|
2015-05-27 17:57:54 -04:00
|
|
|
{'id': this._id, 'completeSample': completeSample, 'validSample': validSample});
|
|
|
|
}
|
|
|
|
}
|