@@ -15,35 +15,132 @@ describe('AppShell Builder', () => {
15
15
beforeEach ( done => host . initialize ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
16
16
afterEach ( done => host . restore ( ) . toPromise ( ) . then ( done , done . fail ) ) ;
17
17
18
+ const targetSpec = { project : 'app' , target : 'app-shell' } ;
19
+
18
20
it ( 'works (basic)' , done => {
19
21
host . replaceInFile ( 'src/app/app.module.ts' , / B r o w s e r M o d u l e / , `
20
22
BrowserModule.withServerTransition({ appId: 'some-app' })
21
23
` ) ;
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 => {
22
36
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
+ ` ,
23
81
'src/app/app.server.module.ts' : `
24
82
import { NgModule } from '@angular/core';
25
83
import { ServerModule } from '@angular/platform-server';
26
84
27
85
import { AppModule } from './app.module';
28
86
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 }];
29
91
30
92
@NgModule({
31
93
imports: [
32
94
AppModule,
33
95
ServerModule,
96
+ RouterModule.forRoot(routes),
34
97
],
35
98
bootstrap: [AppComponent],
99
+ declarations: [AppShellComponent],
36
100
})
37
101
export class AppServerModule {}
38
102
` ,
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
+ ` ,
39
134
} ) ;
40
135
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 (
42
139
tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
43
140
tap ( ( ) => {
44
141
const fileName = 'dist/index.html' ;
45
142
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!' ) ;
47
144
} ) ,
48
145
) . toPromise ( ) . then ( done , done . fail ) ;
49
146
} ) ;
0 commit comments