2016-06-23 12:47:54 -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-06-08 19:38:52 -04:00
|
|
|
import {COMPILER_PROVIDERS, DirectiveResolver, ViewResolver, XHR} from '@angular/compiler';
|
2016-06-24 20:35:01 -04:00
|
|
|
import {MockDirectiveResolver, MockViewResolver, OverridingTestComponentBuilder} from '@angular/compiler/testing';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {APPLICATION_COMMON_PROVIDERS, APP_ID, NgZone, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, RootRenderer} from '@angular/core';
|
2016-06-24 20:35:01 -04:00
|
|
|
import {TestComponentBuilder, TestComponentRenderer} from '@angular/core/testing';
|
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 16:07:17 -04:00
|
|
|
import {AnimationDriver, BROWSER_SANITIZATION_PROVIDERS, DOCUMENT, EVENT_MANAGER_PLUGINS, EventManager} from '@angular/platform-browser';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2016-06-14 20:21:16 -04:00
|
|
|
import {DOMTestComponentRenderer} from '../platform_browser_dynamic_testing_private';
|
2016-06-27 15:27:23 -04:00
|
|
|
import {DomEventsPlugin, DomRootRenderer, DomRootRenderer_, DomSharedStylesHost, ELEMENT_PROBE_PROVIDERS, SharedStylesHost, getDOM} from '../platform_browser_private';
|
2016-06-14 15:34:31 -04:00
|
|
|
import {Parse5DomAdapter} from '../src/parse5_adapter';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2015-12-15 19:38:27 -05:00
|
|
|
function initServerTests() {
|
|
|
|
Parse5DomAdapter.makeCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-14 23:59:44 -04:00
|
|
|
* Default platform providers for testing.
|
2016-06-27 15:27:23 -04:00
|
|
|
*
|
|
|
|
* @experimental
|
2015-12-15 19:38:27 -05:00
|
|
|
*/
|
2016-04-26 00:47:33 -04:00
|
|
|
export const TEST_SERVER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
2016-04-26 01:25:21 -04:00
|
|
|
/*@ts2dart_const*/[
|
2016-04-26 00:47:33 -04:00
|
|
|
PLATFORM_COMMON_PROVIDERS,
|
2016-06-08 19:38:52 -04:00
|
|
|
/*@ts2dart_Provider*/ {
|
|
|
|
provide: PLATFORM_INITIALIZER,
|
|
|
|
useValue: initServerTests,
|
|
|
|
multi: true
|
|
|
|
}
|
2016-04-26 00:58:48 -04:00
|
|
|
];
|
2015-12-15 19:38:27 -05:00
|
|
|
|
|
|
|
function appDoc() {
|
|
|
|
try {
|
2016-04-28 20:50:03 -04:00
|
|
|
return getDOM().defaultDoc();
|
2015-12-15 19:38:27 -05:00
|
|
|
} catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
|
|
|
|
function createNgZone(): NgZone {
|
|
|
|
return new NgZone({enableLongStackTrace: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-15 19:38:27 -05:00
|
|
|
/**
|
|
|
|
* Default application providers for testing.
|
2016-06-27 15:27:23 -04:00
|
|
|
*
|
|
|
|
* @experimental
|
2015-12-15 19:38:27 -05:00
|
|
|
*/
|
|
|
|
export const TEST_SERVER_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
2016-04-26 01:25:21 -04:00
|
|
|
/*@ts2dart_const*/[
|
2016-04-26 00:47:33 -04:00
|
|
|
// TODO(julie: when angular2/platform/server is available, use that instead of making our own
|
2015-12-15 19:38:27 -05:00
|
|
|
// list here.
|
2016-06-08 19:38:52 -04:00
|
|
|
APPLICATION_COMMON_PROVIDERS, COMPILER_PROVIDERS, BROWSER_SANITIZATION_PROVIDERS,
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: DOCUMENT, useFactory: appDoc},
|
|
|
|
/* @ts2dart_Provider */ {provide: DomRootRenderer, useClass: DomRootRenderer_},
|
|
|
|
/* @ts2dart_Provider */ {provide: RootRenderer, useExisting: DomRootRenderer},
|
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 16:07:17 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: AnimationDriver, useValue: AnimationDriver.NOOP},
|
2015-12-15 19:38:27 -05:00
|
|
|
EventManager,
|
2016-06-08 19:38:52 -04:00
|
|
|
/* @ts2dart_Provider */ {
|
|
|
|
provide: EVENT_MANAGER_PLUGINS,
|
|
|
|
useClass: DomEventsPlugin,
|
|
|
|
multi: true
|
|
|
|
},
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: XHR, useClass: XHR},
|
|
|
|
/* @ts2dart_Provider */ {provide: APP_ID, useValue: 'a'},
|
|
|
|
/* @ts2dart_Provider */ {provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
2016-06-08 19:38:52 -04:00
|
|
|
DomSharedStylesHost, ELEMENT_PROBE_PROVIDERS,
|
2016-06-24 20:35:01 -04:00
|
|
|
{provide: TestComponentBuilder, useClass: OverridingTestComponentBuilder},
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
2016-06-23 20:10:22 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: ViewResolver, useClass: MockViewResolver},
|
2016-04-28 20:50:03 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
2016-06-24 15:41:57 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: NgZone, useFactory: createNgZone}
|
2016-04-26 00:58:48 -04:00
|
|
|
];
|