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
|
|
|
|
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, Options, WebDriverExtension} from '../index';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
2016-08-26 19:34:08 -04:00
|
|
|
function createExtension(ids: any[], caps: any) {
|
2016-08-02 18:53:34 -04:00
|
|
|
return new Promise<any>((res, rej) => {
|
|
|
|
try {
|
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
|
|
|
res(Injector
|
|
|
|
.create([
|
2016-10-04 18:57:37 -04:00
|
|
|
ids.map((id) => ({provide: id, useValue: new MockExtension(id)})),
|
2016-08-26 19:34:08 -04:00
|
|
|
{provide: Options.CAPABILITIES, useValue: caps},
|
|
|
|
WebDriverExtension.provideFirstSupported(ids)
|
2016-08-02 18:53:34 -04:00
|
|
|
])
|
|
|
|
.get(WebDriverExtension));
|
|
|
|
} catch (e) {
|
|
|
|
rej(e);
|
|
|
|
}
|
2015-06-26 18:59:18 -04:00
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
describe('WebDriverExtension.provideFirstSupported', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should provide the extension that matches the capabilities',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-08-03 18:00:07 -04:00
|
|
|
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => {
|
|
|
|
expect(m.id).toEqual('m2');
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
it('should throw if there is no match',
|
|
|
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-08-02 18:53:34 -04:00
|
|
|
createExtension(['m1'], {'browser': 'm2'}).catch((err) => {
|
2017-03-02 12:37:01 -05:00
|
|
|
expect(err != null).toBe(true);
|
2015-05-27 17:57:54 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockExtension extends WebDriverExtension {
|
2016-08-26 19:34:08 -04:00
|
|
|
constructor(public id: string) { super(); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
supports(capabilities: {[key: string]: any}): boolean {
|
2016-10-06 18:10:27 -04:00
|
|
|
return capabilities['browser'] === this.id;
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
}
|