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
|
|
|
|
*/
|
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 './init';
|
2016-05-01 14:22:39 -04:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as path from 'path';
|
|
|
|
|
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 {MultipleComponentsMyComp} from '../src/a/multiple_components';
|
|
|
|
import {BasicComp} from '../src/basic';
|
|
|
|
import {createComponent} from './util';
|
2016-06-17 17:09:19 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('template codegen output', () => {
|
2016-05-27 19:22:16 -04:00
|
|
|
const outDir = 'src';
|
2016-05-01 14:22:39 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should lower Decorators without reflect-metadata', () => {
|
2016-05-01 14:22:39 -04:00
|
|
|
const jsOutput = path.join(outDir, 'basic.js');
|
|
|
|
expect(fs.existsSync(jsOutput)).toBeTruthy();
|
|
|
|
expect(fs.readFileSync(jsOutput, {encoding: 'utf-8'})).not.toContain('Reflect.decorate');
|
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should produce metadata.json outputs', () => {
|
2016-05-01 14:22:39 -04:00
|
|
|
const metadataOutput = path.join(outDir, 'basic.metadata.json');
|
|
|
|
expect(fs.existsSync(metadataOutput)).toBeTruthy();
|
|
|
|
const output = fs.readFileSync(metadataOutput, {encoding: 'utf-8'});
|
|
|
|
expect(output).toContain('"decorators":');
|
2016-05-31 14:00:39 -04:00
|
|
|
expect(output).toContain('"module":"@angular/core","name":"Component"');
|
2016-05-01 14:22:39 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should write .d.ts files', () => {
|
2016-05-01 14:22:39 -04:00
|
|
|
const dtsOutput = path.join(outDir, 'basic.d.ts');
|
|
|
|
expect(fs.existsSync(dtsOutput)).toBeTruthy();
|
|
|
|
expect(fs.readFileSync(dtsOutput, {encoding: 'utf-8'})).toContain('Basic');
|
|
|
|
});
|
2016-05-03 20:31:40 -04:00
|
|
|
|
2017-08-02 14:20:07 -04:00
|
|
|
it('should write .ngfactory.js for .d.ts inputs', () => {
|
2017-09-13 19:20:29 -04:00
|
|
|
const factoryOutput = path.join('node_modules', '@angular', 'common', 'common.ngfactory.js');
|
2016-08-18 13:11:06 -04:00
|
|
|
expect(fs.existsSync(factoryOutput)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should be able to create the basic component', () => {
|
2016-10-24 16:28:23 -04:00
|
|
|
const compFixture = createComponent(BasicComp);
|
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
|
|
|
expect(compFixture.componentInstance).toBeTruthy();
|
2016-05-04 13:00:59 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should support ngIf', () => {
|
2016-10-24 16:28:23 -04:00
|
|
|
const compFixture = createComponent(BasicComp);
|
|
|
|
const debugElement = compFixture.debugElement;
|
2016-08-12 17:45:36 -04:00
|
|
|
expect(debugElement.children.length).toBe(3);
|
2016-05-03 20:31:40 -04:00
|
|
|
|
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
|
|
|
compFixture.componentInstance.ctxBool = true;
|
|
|
|
compFixture.detectChanges();
|
2016-08-12 17:45:36 -04:00
|
|
|
expect(debugElement.children.length).toBe(4);
|
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
|
|
|
expect(debugElement.children[2].injector.get(MultipleComponentsMyComp)).toBeTruthy();
|
2016-05-03 20:31:40 -04:00
|
|
|
});
|
2016-05-04 13:00:59 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should support ngFor', () => {
|
2016-10-24 16:28:23 -04:00
|
|
|
const compFixture = createComponent(BasicComp);
|
|
|
|
const debugElement = compFixture.debugElement;
|
2016-08-12 17:45:36 -04:00
|
|
|
expect(debugElement.children.length).toBe(3);
|
2016-05-04 13:00:59 -04:00
|
|
|
|
|
|
|
// test NgFor
|
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
|
|
|
compFixture.componentInstance.ctxArr = [1, 2];
|
|
|
|
compFixture.detectChanges();
|
2016-08-12 17:45:36 -04:00
|
|
|
expect(debugElement.children.length).toBe(5);
|
2016-05-04 13:00:59 -04:00
|
|
|
expect(debugElement.children[2].attributes['value']).toBe('1');
|
|
|
|
expect(debugElement.children[3].attributes['value']).toBe('2');
|
|
|
|
});
|
2016-08-12 17:45:36 -04:00
|
|
|
|
|
|
|
describe('i18n', () => {
|
|
|
|
it('should inject the locale into the component', () => {
|
|
|
|
const compFixture = createComponent(BasicComp);
|
|
|
|
expect(compFixture.componentInstance.localeId).toEqual('fi');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject the translations format into the component', () => {
|
|
|
|
const compFixture = createComponent(BasicComp);
|
2016-08-13 01:13:54 -04:00
|
|
|
expect(compFixture.componentInstance.translationsFormat).toEqual('xlf');
|
2016-08-12 17:45:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should support i18n for content tags', () => {
|
2016-10-24 16:28:23 -04:00
|
|
|
const containerElement = createComponent(BasicComp).nativeElement;
|
2017-08-08 05:17:40 -04:00
|
|
|
const pElement = containerElement.querySelector('p');
|
|
|
|
const pText = pElement.textContent;
|
2016-08-12 17:45:36 -04:00
|
|
|
expect(pText).toBe('tervetuloa');
|
|
|
|
});
|
2017-07-07 19:16:49 -04:00
|
|
|
|
|
|
|
it('should have removed i18n markup', () => {
|
|
|
|
const containerElement = createComponent(BasicComp).debugElement.children[0];
|
|
|
|
expect(containerElement.attributes['title']).toBe('käännä teksti');
|
|
|
|
expect(containerElement.attributes['i18n-title']).toBeUndefined();
|
|
|
|
});
|
2016-08-12 17:45:36 -04:00
|
|
|
});
|
2016-05-27 19:22:16 -04:00
|
|
|
});
|