@@ -70,6 +70,84 @@ describe('Server Schematic', () => {
70
70
) ;
71
71
} ) ;
72
72
73
+ it ( 'should account for renamed app component and module' , async ( ) => {
74
+ appTree . create (
75
+ '/projects/bar/src/app/my-custom-module.ts' ,
76
+ `
77
+ import { NgModule } from '@angular/core';
78
+ import { BrowserModule } from '@angular/platform-browser';
79
+ import { MyCustomApp } from './foo/bar/baz/app.foo';
80
+
81
+ @NgModule({
82
+ declarations: [MyCustomApp],
83
+ imports: [BrowserModule],
84
+ bootstrap: [MyCustomApp]
85
+ })
86
+ export class MyCustomModule {}
87
+ ` ,
88
+ ) ;
89
+
90
+ appTree . overwrite (
91
+ '/projects/bar/src/main.ts' ,
92
+ `
93
+ import { platformBrowser } from '@angular/platform-browser';
94
+ import { MyCustomModule } from './app/my-custom-module';
95
+
96
+ platformBrowser().bootstrapModule(MyCustomModule)
97
+ .catch(err => console.error(err));
98
+ ` ,
99
+ ) ;
100
+
101
+ const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
102
+ const filePath = '/projects/bar/src/app/app.module.server.ts' ;
103
+ expect ( tree . exists ( filePath ) ) . toBeTrue ( ) ;
104
+ const contents = tree . readContent ( filePath ) ;
105
+
106
+ expect ( contents ) . toContain ( `import { MyCustomApp } from './foo/bar/baz/app.foo';` ) ;
107
+ expect ( contents ) . toContain ( `import { MyCustomModule } from './my-custom-module';` ) ;
108
+ expect ( contents ) . toContain ( `imports: [MyCustomModule],` ) ;
109
+ expect ( contents ) . toContain ( `bootstrap: [MyCustomApp],` ) ;
110
+ } ) ;
111
+
112
+ it ( 'should account for renamed app component and module that have been aliased' , async ( ) => {
113
+ appTree . create (
114
+ '/projects/bar/src/app/my-custom-module.ts' ,
115
+ `
116
+ import { NgModule } from '@angular/core';
117
+ import { BrowserModule } from '@angular/platform-browser';
118
+ import { MyCustomApp as MyAliasedApp } from './foo/bar/baz/app.foo';
119
+
120
+ @NgModule({
121
+ declarations: [MyAliasedApp],
122
+ imports: [BrowserModule],
123
+ bootstrap: [MyAliasedApp]
124
+ })
125
+ export class MyCustomModule {}
126
+ ` ,
127
+ ) ;
128
+
129
+ appTree . overwrite (
130
+ '/projects/bar/src/main.ts' ,
131
+ `
132
+ import { platformBrowser } from '@angular/platform-browser';
133
+ import { MyCustomModule as MyAliasedModule } from './app/my-custom-module';
134
+
135
+ platformBrowser().bootstrapModule(MyAliasedModule)
136
+ .catch(err => console.error(err));
137
+ ` ,
138
+ ) ;
139
+
140
+ const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
141
+ const filePath = '/projects/bar/src/app/app.module.server.ts' ;
142
+ expect ( tree . exists ( filePath ) ) . toBeTrue ( ) ;
143
+ const contents = tree . readContent ( filePath ) ;
144
+
145
+ expect ( contents ) . toContain ( `import { MyCustomApp } from './foo/bar/baz/app.foo';` ) ;
146
+ expect ( contents ) . toContain ( `import { MyCustomModule } from './my-custom-module';` ) ;
147
+ expect ( contents ) . toContain ( `imports: [MyCustomModule],` ) ;
148
+ expect ( contents ) . toContain ( `bootstrap: [MyCustomApp],` ) ;
149
+ } ) ;
150
+
73
151
it ( 'should add dependency: @angular/platform-server' , async ( ) => {
74
152
const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
75
153
const filePath = '/package.json' ;
@@ -127,6 +205,48 @@ describe('Server Schematic', () => {
127
205
expect ( contents ) . toContain ( `bootstrapApplication(App, config)` ) ;
128
206
} ) ;
129
207
208
+ it ( 'should account for renamed app component' , async ( ) => {
209
+ appTree . overwrite (
210
+ '/projects/bar/src/main.ts' ,
211
+ `
212
+ import { bootstrapApplication } from '@angular/platform-browser';
213
+ import { appConfig } from './app/app.config';
214
+ import { MyCustomApp } from './foo/bar/baz/app.foo';
215
+
216
+ bootstrapApplication(MyCustomApp, appConfig)
217
+ .catch((err) => console.error(err));
218
+ ` ,
219
+ ) ;
220
+
221
+ const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
222
+ const filePath = '/projects/bar/src/main.server.ts' ;
223
+ expect ( tree . exists ( filePath ) ) . toBeTrue ( ) ;
224
+ const contents = tree . readContent ( filePath ) ;
225
+ expect ( contents ) . toContain ( `import { MyCustomApp } from './foo/bar/baz/app.foo';` ) ;
226
+ expect ( contents ) . toContain ( `bootstrapApplication(MyCustomApp, config)` ) ;
227
+ } ) ;
228
+
229
+ it ( 'should account for renamed app component that is aliased within the main file' , async ( ) => {
230
+ appTree . overwrite (
231
+ '/projects/bar/src/main.ts' ,
232
+ `
233
+ import { bootstrapApplication } from '@angular/platform-browser';
234
+ import { appConfig } from './app/app.config';
235
+ import { MyCustomApp as MyCustomAlias } from './foo/bar/baz/app.foo';
236
+
237
+ bootstrapApplication(MyCustomAlias, appConfig)
238
+ .catch((err) => console.error(err));
239
+ ` ,
240
+ ) ;
241
+
242
+ const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
243
+ const filePath = '/projects/bar/src/main.server.ts' ;
244
+ expect ( tree . exists ( filePath ) ) . toBeTrue ( ) ;
245
+ const contents = tree . readContent ( filePath ) ;
246
+ expect ( contents ) . toContain ( `import { MyCustomApp } from './foo/bar/baz/app.foo';` ) ;
247
+ expect ( contents ) . toContain ( `bootstrapApplication(MyCustomApp, config)` ) ;
248
+ } ) ;
249
+
130
250
it ( 'should create server app config file' , async ( ) => {
131
251
const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
132
252
const filePath = '/projects/bar/src/app/app.config.server.ts' ;
0 commit comments