@@ -40,63 +40,71 @@ describe('App Shell Schematic', () => {
40
40
41
41
beforeEach ( async ( ) => {
42
42
appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
43
- appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
44
43
} ) ;
45
44
46
- it ( 'should add app shell configuration' , async ( ) => {
47
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
48
- const filePath = '/angular.json' ;
49
- const content = tree . readContent ( filePath ) ;
50
- const workspace = JSON . parse ( content ) ;
51
- const target = workspace . projects . bar . architect [ 'build' ] ;
52
- expect ( target . configurations . production . appShell ) . toBeTrue ( ) ;
53
- } ) ;
45
+ describe ( 'non standalone application' , ( ) => {
46
+ beforeEach ( async ( ) => {
47
+ appTree = await schematicRunner . runSchematic (
48
+ 'application' ,
49
+ { ... appOptions , standalone : false } ,
50
+ appTree ,
51
+ ) ;
52
+ } ) ;
54
53
55
- it ( 'should ensure the client app has a router-outlet' , async ( ) => {
56
- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
57
- appTree = await schematicRunner . runSchematic (
58
- 'application' ,
59
- { ...appOptions , routing : false } ,
60
- appTree ,
61
- ) ;
62
- await expectAsync (
63
- schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ,
64
- ) . toBeRejected ( ) ;
65
- } ) ;
54
+ it ( 'should add app shell configuration' , async ( ) => {
55
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
56
+ const filePath = '/angular.json' ;
57
+ const content = tree . readContent ( filePath ) ;
58
+ const workspace = JSON . parse ( content ) ;
59
+ const target = workspace . projects . bar . architect [ 'build' ] ;
60
+ expect ( target . configurations . production . appShell ) . toBeTrue ( ) ;
61
+ } ) ;
66
62
67
- it ( 'should add a server app' , async ( ) => {
68
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
69
- const filePath = '/projects/bar/src/app/app.module.server.ts' ;
70
- expect ( tree . exists ( filePath ) ) . toEqual ( true ) ;
71
- } ) ;
63
+ it ( 'should ensure the client app has a router-outlet' , async ( ) => {
64
+ appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
65
+ appTree = await schematicRunner . runSchematic (
66
+ 'application' ,
67
+ { ...appOptions , routing : false } ,
68
+ appTree ,
69
+ ) ;
70
+ await expectAsync (
71
+ schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ,
72
+ ) . toBeRejected ( ) ;
73
+ } ) ;
72
74
73
- it ( 'should add router module to client app module' , async ( ) => {
74
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
75
- const filePath = '/projects/bar/src/app/app.module.ts' ;
76
- const content = tree . readContent ( filePath ) ;
77
- expect ( content ) . toMatch ( / i m p o r t { R o u t e r M o d u l e } f r o m ' @ a n g u l a r \/ r o u t e r ' ; / ) ;
78
- } ) ;
75
+ it ( 'should add a server app' , async ( ) => {
76
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
77
+ const filePath = '/projects/bar/src/app/app.module.server.ts' ;
78
+ expect ( tree . exists ( filePath ) ) . toEqual ( true ) ;
79
+ } ) ;
79
80
80
- it ( 'should not fail when AppModule have imported RouterModule already' , async ( ) => {
81
- const updateRecorder = appTree . beginUpdate ( '/projects/bar/src/app/app.module.ts' ) ;
82
- updateRecorder . insertLeft ( 0 , "import { RouterModule } from '@angular/router';" ) ;
83
- appTree . commitUpdate ( updateRecorder ) ;
81
+ it ( 'should add router module to client app module' , async ( ) => {
82
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
83
+ const filePath = '/projects/bar/src/app/app.module.ts' ;
84
+ const content = tree . readContent ( filePath ) ;
85
+ expect ( content ) . toMatch ( / i m p o r t { R o u t e r M o d u l e } f r o m ' @ a n g u l a r \/ r o u t e r ' ; / ) ;
86
+ } ) ;
84
87
85
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
86
- const filePath = '/projects/bar/src/app/app.module.ts' ;
87
- const content = tree . readContent ( filePath ) ;
88
- expect ( content ) . toMatch ( / i m p o r t { R o u t e r M o d u l e } f r o m ' @ a n g u l a r \/ r o u t e r ' ; / ) ;
89
- } ) ;
88
+ it ( 'should not fail when AppModule have imported RouterModule already' , async ( ) => {
89
+ const updateRecorder = appTree . beginUpdate ( '/projects/bar/src/app/app.module.ts' ) ;
90
+ updateRecorder . insertLeft ( 0 , "import { RouterModule } from '@angular/router';" ) ;
91
+ appTree . commitUpdate ( updateRecorder ) ;
90
92
91
- describe ( 'Add router-outlet' , ( ) => {
92
- function makeInlineTemplate ( tree : UnitTestTree , template ?: string ) : void {
93
- template =
94
- template ||
95
- `
93
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
94
+ const filePath = '/projects/bar/src/app/app.module.ts' ;
95
+ const content = tree . readContent ( filePath ) ;
96
+ expect ( content ) . toMatch ( / i m p o r t { R o u t e r M o d u l e } f r o m ' @ a n g u l a r \/ r o u t e r ' ; / ) ;
97
+ } ) ;
98
+
99
+ describe ( 'Add router-outlet' , ( ) => {
100
+ function makeInlineTemplate ( tree : UnitTestTree , template ?: string ) : void {
101
+ template =
102
+ template ||
103
+ `
96
104
<p>
97
105
App works!
98
106
</p>` ;
99
- const newText = `
107
+ const newText = `
100
108
import { Component } from '@angular/core';
101
109
102
110
@Component({
@@ -109,112 +117,100 @@ describe('App Shell Schematic', () => {
109
117
export class AppComponent { }
110
118
111
119
` ;
112
- tree . overwrite ( '/projects/bar/src/app/app.component.ts' , newText ) ;
113
- tree . delete ( '/projects/bar/src/app/app.component.html' ) ;
114
- }
115
-
116
- it ( 'should not re-add the router outlet (external template)' , async ( ) => {
117
- const htmlPath = '/projects/bar/src/app/app.component.html' ;
118
- appTree . overwrite ( htmlPath , '<router-outlet></router-outlet>' ) ;
119
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
120
- const content = tree . readContent ( htmlPath ) ;
121
- const matches = content . match ( / < r o u t e r - o u t l e t > < \/ r o u t e r - o u t l e t > / g) ;
122
- const numMatches = matches ? matches . length : 0 ;
123
- expect ( numMatches ) . toEqual ( 1 ) ;
120
+ tree . overwrite ( '/projects/bar/src/app/app.component.ts' , newText ) ;
121
+ tree . delete ( '/projects/bar/src/app/app.component.html' ) ;
122
+ }
123
+
124
+ it ( 'should not re-add the router outlet (external template)' , async ( ) => {
125
+ const htmlPath = '/projects/bar/src/app/app.component.html' ;
126
+ appTree . overwrite ( htmlPath , '<router-outlet></router-outlet>' ) ;
127
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
128
+ const content = tree . readContent ( htmlPath ) ;
129
+ const matches = content . match ( / < r o u t e r - o u t l e t > < \/ r o u t e r - o u t l e t > / g) ;
130
+ const numMatches = matches ? matches . length : 0 ;
131
+ expect ( numMatches ) . toEqual ( 1 ) ;
132
+ } ) ;
133
+
134
+ it ( 'should not re-add the router outlet (inline template)' , async ( ) => {
135
+ makeInlineTemplate ( appTree , '<router-outlet></router-outlet>' ) ;
136
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
137
+ const content = tree . readContent ( '/projects/bar/src/app/app.component.ts' ) ;
138
+ const matches = content . match ( / < r o u t e r - o u t l e t > < \/ r o u t e r - o u t l e t > / g) ;
139
+ const numMatches = matches ? matches . length : 0 ;
140
+ expect ( numMatches ) . toEqual ( 1 ) ;
141
+ } ) ;
124
142
} ) ;
125
143
126
- it ( 'should not re-add the router outlet (inline template)' , async ( ) => {
127
- makeInlineTemplate ( appTree , '<router-outlet></router-outlet>' ) ;
144
+ it ( 'should add router imports to server module' , async ( ) => {
128
145
const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
129
- const content = tree . readContent ( '/projects/bar/src/app/app.component.ts' ) ;
130
- const matches = content . match ( / < r o u t e r - o u t l e t > < \/ r o u t e r - o u t l e t > / g) ;
131
- const numMatches = matches ? matches . length : 0 ;
132
- expect ( numMatches ) . toEqual ( 1 ) ;
146
+ const filePath = '/projects/bar/src/app/app.module.server.ts' ;
147
+ const content = tree . readContent ( filePath ) ;
148
+ expect ( content ) . toMatch ( / i m p o r t { R o u t e s , R o u t e r M o d u l e } f r o m ' @ a n g u l a r \/ r o u t e r ' ; / ) ;
133
149
} ) ;
134
- } ) ;
135
-
136
- it ( 'should add router imports to server module' , async ( ) => {
137
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
138
- const filePath = '/projects/bar/src/app/app.module.server.ts' ;
139
- const content = tree . readContent ( filePath ) ;
140
- expect ( content ) . toMatch ( / i m p o r t { R o u t e s , R o u t e r M o d u l e } f r o m ' @ a n g u l a r \/ r o u t e r ' ; / ) ;
141
- } ) ;
142
150
143
- it ( 'should work if server config was added prior to running the app-shell schematic' , async ( ) => {
144
- let tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
145
- tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , tree ) ;
146
- expect ( tree . exists ( '/projects/bar/src/app/app-shell/app-shell.component.ts' ) ) . toBe ( true ) ;
147
- } ) ;
151
+ it ( 'should work if server config was added prior to running the app-shell schematic' , async ( ) => {
152
+ let tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
153
+ tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , tree ) ;
154
+ expect ( tree . exists ( '/projects/bar/src/app/app-shell/app-shell.component.ts' ) ) . toBe ( true ) ;
155
+ } ) ;
148
156
149
- it ( 'should define a server route' , async ( ) => {
150
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
151
- const filePath = '/projects/bar/src/app/app.module.server.ts' ;
152
- const content = tree . readContent ( filePath ) ;
153
- expect ( content ) . toMatch ( / c o n s t r o u t e s : R o u t e s = \[ / ) ;
154
- } ) ;
157
+ it ( 'should define a server route' , async ( ) => {
158
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
159
+ const filePath = '/projects/bar/src/app/app.module.server.ts' ;
160
+ const content = tree . readContent ( filePath ) ;
161
+ expect ( content ) . toMatch ( / c o n s t r o u t e s : R o u t e s = \[ / ) ;
162
+ } ) ;
155
163
156
- it ( 'should import RouterModule with forRoot' , async ( ) => {
157
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
158
- const filePath = '/projects/bar/src/app/app.module.server.ts' ;
159
- const content = tree . readContent ( filePath ) ;
160
- expect ( content ) . toMatch (
161
- / c o n s t r o u t e s : R o u t e s = \[ { p a t h : ' s h e l l ' , c o m p o n e n t : A p p S h e l l C o m p o n e n t } \] ; / ,
162
- ) ;
163
- expect ( content ) . toMatch ( / S e r v e r M o d u l e , \r ? \n \s * R o u t e r M o d u l e \. f o r R o o t \( r o u t e s \) , / ) ;
164
- } ) ;
164
+ it ( 'should import RouterModule with forRoot' , async ( ) => {
165
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
166
+ const filePath = '/projects/bar/src/app/app.module.server.ts' ;
167
+ const content = tree . readContent ( filePath ) ;
168
+ expect ( content ) . toMatch (
169
+ / c o n s t r o u t e s : R o u t e s = \[ { p a t h : ' s h e l l ' , c o m p o n e n t : A p p S h e l l C o m p o n e n t } \] ; / ,
170
+ ) ;
171
+ expect ( content ) . toMatch ( / S e r v e r M o d u l e , \r ? \n \s * R o u t e r M o d u l e \. f o r R o o t \( r o u t e s \) , / ) ;
172
+ } ) ;
165
173
166
- it ( 'should create the shell component' , async ( ) => {
167
- const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
168
- expect ( tree . exists ( '/projects/bar/src/app/app-shell/app-shell.component.ts' ) ) . toBe ( true ) ;
169
- const content = tree . readContent ( '/projects/bar/src/app/app.module.server.ts' ) ;
170
- expect ( content ) . toMatch ( / a p p - s h e l l \. c o m p o n e n t / ) ;
174
+ it ( 'should create the shell component' , async ( ) => {
175
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
176
+ expect ( tree . exists ( '/projects/bar/src/app/app-shell/app-shell.component.ts' ) ) . toBe ( true ) ;
177
+ const content = tree . readContent ( '/projects/bar/src/app/app.module.server.ts' ) ;
178
+ expect ( content ) . toMatch ( / a p p - s h e l l \. c o m p o n e n t / ) ;
179
+ } ) ;
171
180
} ) ;
172
181
173
182
describe ( 'standalone application' , ( ) => {
174
- const standaloneAppName = 'baz' ;
175
- const standaloneAppOptions : ApplicationOptions = {
176
- ...appOptions ,
177
- name : standaloneAppName ,
178
- standalone : true ,
179
- } ;
180
- const defaultStandaloneOptions : AppShellOptions = {
181
- project : standaloneAppName ,
182
- } ;
183
-
184
183
beforeEach ( async ( ) => {
185
- appTree = await schematicRunner . runSchematic ( 'application' , standaloneAppOptions , appTree ) ;
184
+ appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
186
185
} ) ;
187
186
188
187
it ( 'should ensure the client app has a router-outlet' , async ( ) => {
189
- appTree = await schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
188
+ const appName = 'baz' ;
190
189
appTree = await schematicRunner . runSchematic (
191
190
'application' ,
192
- { ...standaloneAppOptions , routing : false } ,
191
+ {
192
+ ...appOptions ,
193
+ name : appName ,
194
+ routing : false ,
195
+ } ,
193
196
appTree ,
194
197
) ;
198
+
195
199
await expectAsync (
196
- schematicRunner . runSchematic ( 'app-shell' , defaultStandaloneOptions , appTree ) ,
200
+ schematicRunner . runSchematic ( 'app-shell' , { ... defaultOptions , project : appName } , appTree ) ,
197
201
) . toBeRejected ( ) ;
198
202
} ) ;
199
203
200
204
it ( 'should create the shell component' , async ( ) => {
201
- const tree = await schematicRunner . runSchematic (
202
- 'app-shell' ,
203
- defaultStandaloneOptions ,
204
- appTree ,
205
- ) ;
206
- expect ( tree . exists ( '/projects/baz/src/app/app-shell/app-shell.component.ts' ) ) . toBe ( true ) ;
207
- const content = tree . readContent ( '/projects/baz/src/app/app.config.server.ts' ) ;
205
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
206
+ expect ( tree . exists ( '/projects/bar/src/app/app-shell/app-shell.component.ts' ) ) . toBe ( true ) ;
207
+ const content = tree . readContent ( '/projects/bar/src/app/app.config.server.ts' ) ;
208
208
expect ( content ) . toMatch ( / a p p - s h e l l \. c o m p o n e n t / ) ;
209
209
} ) ;
210
210
211
211
it ( 'should define a server route' , async ( ) => {
212
- const tree = await schematicRunner . runSchematic (
213
- 'app-shell' ,
214
- defaultStandaloneOptions ,
215
- appTree ,
216
- ) ;
217
- const filePath = '/projects/baz/src/app/app.config.server.ts' ;
212
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
213
+ const filePath = '/projects/bar/src/app/app.config.server.ts' ;
218
214
const content = tree . readContent ( filePath ) ;
219
215
expect ( tags . oneLine `${ content } ` ) . toContain ( tags . oneLine `{
220
216
provide: ROUTES,
@@ -229,23 +225,15 @@ describe('App Shell Schematic', () => {
229
225
} ) ;
230
226
231
227
it ( `should add import to 'ROUTES' token from '@angular/router'` , async ( ) => {
232
- const tree = await schematicRunner . runSchematic (
233
- 'app-shell' ,
234
- defaultStandaloneOptions ,
235
- appTree ,
236
- ) ;
237
- const filePath = '/projects/baz/src/app/app.config.server.ts' ;
228
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
229
+ const filePath = '/projects/bar/src/app/app.config.server.ts' ;
238
230
const content = tree . readContent ( filePath ) ;
239
231
expect ( content ) . toContain ( `import { ROUTES } from '@angular/router';` ) ;
240
232
} ) ;
241
233
242
234
it ( `should add import to 'AppShellComponent'` , async ( ) => {
243
- const tree = await schematicRunner . runSchematic (
244
- 'app-shell' ,
245
- defaultStandaloneOptions ,
246
- appTree ,
247
- ) ;
248
- const filePath = '/projects/baz/src/app/app.config.server.ts' ;
235
+ const tree = await schematicRunner . runSchematic ( 'app-shell' , defaultOptions , appTree ) ;
236
+ const filePath = '/projects/bar/src/app/app.config.server.ts' ;
249
237
const content = tree . readContent ( filePath ) ;
250
238
expect ( content ) . toContain (
251
239
`import { AppShellComponent } from './app-shell/app-shell.component';` ,
@@ -275,7 +263,8 @@ describe('App Shell Schematic', () => {
275
263
appTree . overwrite ( '/angular.json' , JSON . stringify ( config , undefined , 2 ) ) ;
276
264
}
277
265
278
- beforeEach ( ( ) => {
266
+ beforeEach ( async ( ) => {
267
+ appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
279
268
convertBuilderToLegacyBrowser ( ) ;
280
269
} ) ;
281
270
0 commit comments