@@ -15,35 +15,132 @@ describe('AppShell Builder', () => {
1515 beforeEach ( done => host . initialize ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
1616 afterEach ( done => host . restore ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
1717
18+ const targetSpec = { project : 'app' , target : 'app-shell' } ;
19+
1820 it ( 'works (basic)' , done => {
1921 host . replaceInFile ( 'src/app/app.module.ts' , / B r o w s e r M o d u l e / , `
2022 BrowserModule.withServerTransition({ appId: 'some-app' })
2123 ` ) ;
24+
25+ runTargetSpec ( host , targetSpec , { } , DefaultTimeout * 2 ) . pipe (
26+ tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
27+ tap ( ( ) => {
28+ const fileName = 'dist/index.html' ;
29+ const content = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( fileName ) ) ) ;
30+ expect ( content ) . toMatch ( / W e l c o m e t o a p p ! / ) ;
31+ } ) ,
32+ ) . toPromise ( ) . then ( done , done . fail ) ;
33+ } ) ;
34+
35+ it ( 'works with route' , done => {
2236 host . writeMultipleFiles ( {
37+ 'src/app/app-shell/app-shell.component.html' : `
38+ <p>
39+ app-shell works!
40+ </p>
41+ ` ,
42+ 'src/app/app-shell/app-shell.component.ts' : `
43+ import { Component, OnInit } from '@angular/core';
44+
45+ @Component({
46+ selector: 'app-app-shell',
47+ templateUrl: './app-shell.component.html',
48+ })
49+ export class AppShellComponent implements OnInit {
50+
51+ constructor() { }
52+
53+ ngOnInit() {
54+ }
55+
56+ }
57+ ` ,
58+ 'src/app/app.module.ts' : `
59+ import { BrowserModule } from '@angular/platform-browser';
60+ import { NgModule } from '@angular/core';
61+
62+ import { AppRoutingModule } from './app-routing.module';
63+ import { AppComponent } from './app.component';
64+ import { environment } from '../environments/environment';
65+ import { RouterModule } from '@angular/router';
66+
67+ @NgModule({
68+ declarations: [
69+ AppComponent
70+ ],
71+ imports: [
72+ BrowserModule.withServerTransition({ appId: 'serverApp' }),
73+ AppRoutingModule,
74+ RouterModule
75+ ],
76+ providers: [],
77+ bootstrap: [AppComponent]
78+ })
79+ export class AppModule { }
80+ ` ,
2381 'src/app/app.server.module.ts' : `
2482 import { NgModule } from '@angular/core';
2583 import { ServerModule } from '@angular/platform-server';
2684
2785 import { AppModule } from './app.module';
2886 import { AppComponent } from './app.component';
87+ import { Routes, RouterModule } from '@angular/router';
88+ import { AppShellComponent } from './app-shell/app-shell.component';
89+
90+ const routes: Routes = [ { path: 'shell', component: AppShellComponent }];
2991
3092 @NgModule({
3193 imports: [
3294 AppModule,
3395 ServerModule,
96+ RouterModule.forRoot(routes),
3497 ],
3598 bootstrap: [AppComponent],
99+ declarations: [AppShellComponent],
36100 })
37101 export class AppServerModule {}
38102 ` ,
103+ 'src/main.ts' : `
104+ import { enableProdMode } from '@angular/core';
105+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
106+
107+ import { AppModule } from './app/app.module';
108+ import { environment } from './environments/environment';
109+
110+ if (environment.production) {
111+ enableProdMode();
112+ }
113+
114+ document.addEventListener('DOMContentLoaded', () => {
115+ platformBrowserDynamic().bootstrapModule(AppModule)
116+ .catch(err => console.log(err));
117+ });
118+ ` ,
119+ 'src/app/app-routing.module.ts' : `
120+ import { NgModule } from '@angular/core';
121+ import { Routes, RouterModule } from '@angular/router';
122+
123+ const routes: Routes = [];
124+
125+ @NgModule({
126+ imports: [RouterModule.forRoot(routes)],
127+ exports: [RouterModule]
128+ })
129+ export class AppRoutingModule { }
130+ ` ,
131+ 'src/app/app.component.html' : `
132+ <router-outlet></router-outlet>
133+ ` ,
39134 } ) ;
40135
41- runTargetSpec ( host , { project : 'app' , target : 'app-shell' } , DefaultTimeout * 2 ) . pipe (
136+ const overrides = { route : 'shell' } ;
137+
138+ runTargetSpec ( host , targetSpec , overrides , DefaultTimeout * 2 ) . pipe (
42139 tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
43140 tap ( ( ) => {
44141 const fileName = 'dist/index.html' ;
45142 const content = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( fileName ) ) ) ;
46- expect ( content ) . toMatch ( / W e l c o m e t o a p p ! / ) ;
143+ expect ( content ) . toContain ( ' app-shell works!' ) ;
47144 } ) ,
48145 ) . toPromise ( ) . then ( done , done . fail ) ;
49146 } ) ;
0 commit comments