@@ -29,11 +29,9 @@ describe('Schematic Tests Nest Add', () => {
29
29
nestTree = await createTestNest ( runner ) ;
30
30
} ) ;
31
31
32
- it ( 'should handle nest add for default app ' , async ( ) => {
32
+ it ( 'should add azure func for default setup ' , async ( ) => {
33
33
const options : Schema = {
34
- sourceRoot : 'src' ,
35
34
skipInstall : true ,
36
- rootDir : 'src' ,
37
35
rootModuleFileName : 'app.module' ,
38
36
rootModuleClassName : 'AppModule'
39
37
} ;
@@ -68,20 +66,20 @@ describe('Schematic Tests Nest Add', () => {
68
66
] ) ;
69
67
} ) ;
70
68
71
- it ( 'should handle nest add for project' , async ( ) => {
69
+ it ( 'should add azure-func for monorepo app' , async ( ) => {
70
+ const projectName = 'azure-2' ;
72
71
const options : Schema = {
73
- sourceRoot : '/libs/lib1/src' ,
74
72
skipInstall : true ,
75
- rootDir : 'src' ,
76
- project : 'lib1'
73
+ project : projectName ,
74
+ sourceRoot : `apps/ ${ projectName } /src`
77
75
} ;
76
+
78
77
await runner
79
78
. runExternalSchematicAsync (
80
79
'@nestjs/schematics' ,
81
- 'library ' ,
80
+ 'sub-app ' ,
82
81
{
83
- name : 'lib1' ,
84
- prefix : '@app'
82
+ name : projectName
85
83
} ,
86
84
nestTree
87
85
)
@@ -90,6 +88,7 @@ describe('Schematic Tests Nest Add', () => {
90
88
const tree = await runner
91
89
. runSchematicAsync ( 'nest-add' , options , nestTree )
92
90
. toPromise ( ) ;
91
+
93
92
const files : string [ ] = tree . files ;
94
93
expect ( files ) . toEqual ( [
95
94
'/.eslintrc.js' ,
@@ -106,37 +105,41 @@ describe('Schematic Tests Nest Add', () => {
106
105
'/src/main.ts' ,
107
106
'/test/app.e2e-spec.ts' ,
108
107
'/test/jest-e2e.json' ,
109
- '/libs/lib1/tsconfig.lib.json' ,
110
- '/libs/lib1/src/index.ts' ,
111
- '/libs/lib1/src/lib1.module.ts' ,
112
- '/libs/lib1/src/lib1.service.spec.ts' ,
113
- '/libs/lib1/src/lib1.service.ts' ,
114
- '/libs/lib1/src/.funcignore' ,
115
- '/libs/lib1/src/host.json' ,
116
- '/libs/lib1/src/local.settings.json' ,
117
- '/libs/lib1/src/main.azure.ts' ,
118
- '/libs/lib1/src/proxies.json' ,
119
- '/libs/lib1/src/webpack.config.js' ,
120
- '/libs/lib1/src/main/function.json' ,
121
- '/libs/lib1/src/main/index.ts' ,
122
- '/libs/lib1/src/main/sample.dat'
108
+ '/apps/nestjs-azure-func-http/tsconfig.app.json' ,
109
+ `/apps/${ projectName } /tsconfig.app.json` ,
110
+ `/apps/${ projectName } /src/app.controller.spec.ts` ,
111
+ `/apps/${ projectName } /src/app.controller.ts` ,
112
+ `/apps/${ projectName } /src/app.module.ts` ,
113
+ `/apps/${ projectName } /src/app.service.ts` ,
114
+ `/apps/${ projectName } /src/main.ts` ,
115
+ `/apps/${ projectName } /src/.funcignore` ,
116
+ `/apps/${ projectName } /src/host.json` ,
117
+ `/apps/${ projectName } /src/local.settings.json` ,
118
+ `/apps/${ projectName } /src/main.azure.ts` ,
119
+ `/apps/${ projectName } /src/proxies.json` ,
120
+ `/apps/${ projectName } /src/webpack.config.js` ,
121
+ `/apps/${ projectName } /src/main/function.json` ,
122
+ `/apps/${ projectName } /src/main/index.ts` ,
123
+ `/apps/${ projectName } /src/main/sample.dat` ,
124
+ `/apps/${ projectName } /test/app.e2e-spec.ts` ,
125
+ `/apps/${ projectName } /test/jest-e2e.json`
123
126
] ) ;
124
127
} ) ;
125
128
126
- it ( 'should have a nest-cli.json for project' , async ( ) => {
129
+ it ( 'should have a nest-cli.json for monorepo app' , async ( ) => {
130
+ const projectName = 'azure-2' ;
127
131
const options : Schema = {
128
- sourceRoot : '/libs/lib1/src' ,
129
132
skipInstall : true ,
130
- rootDir : 'src' ,
131
- project : 'lib1'
133
+ project : projectName ,
134
+ sourceRoot : `apps/ ${ projectName } /src`
132
135
} ;
136
+
133
137
await runner
134
138
. runExternalSchematicAsync (
135
139
'@nestjs/schematics' ,
136
- 'library ' ,
140
+ 'sub-app ' ,
137
141
{
138
- name : 'lib1' ,
139
- prefix : '@app'
142
+ name : projectName
140
143
} ,
141
144
nestTree
142
145
)
@@ -147,10 +150,12 @@ describe('Schematic Tests Nest Add', () => {
147
150
. toPromise ( ) ;
148
151
const fileContent = getFileContent ( tree , '/nest-cli.json' ) ;
149
152
const parsedFile = JSON . parse ( fileContent ) ;
150
- expect ( parsedFile . projects . lib1 . sourceRoot ) . toEqual ( 'libs/lib1/src' ) ;
153
+ expect ( parsedFile . projects [ projectName ] . sourceRoot ) . toEqual (
154
+ `apps/${ projectName } /src`
155
+ ) ;
151
156
} ) ;
152
157
153
- it ( 'should a nest-cli.json for default app' , async ( ) => {
158
+ it ( 'should have a nest-cli.json for default app' , async ( ) => {
154
159
const options : Schema = {
155
160
sourceRoot : 'src' ,
156
161
skipInstall : true ,
@@ -167,20 +172,20 @@ describe('Schematic Tests Nest Add', () => {
167
172
expect ( fileContent ) . toContain ( `"sourceRoot": "src"` ) ;
168
173
} ) ;
169
174
170
- it ( 'should import the app.module int main azure file for project' , async ( ) => {
175
+ it ( 'should import the app.module int main azure file for monorepo app' , async ( ) => {
176
+ const projectName = 'azure-2' ;
171
177
const options : Schema = {
172
- sourceRoot : '/libs/lib1/src' ,
173
178
skipInstall : true ,
174
- rootDir : 'src' ,
175
- project : 'lib1'
179
+ project : projectName ,
180
+ sourceRoot : `apps/ ${ projectName } /src`
176
181
} ;
182
+
177
183
await runner
178
184
. runExternalSchematicAsync (
179
185
'@nestjs/schematics' ,
180
- 'library ' ,
186
+ 'sub-app ' ,
181
187
{
182
- name : 'lib1' ,
183
- prefix : '@app'
188
+ name : projectName
184
189
} ,
185
190
nestTree
186
191
)
@@ -189,7 +194,10 @@ describe('Schematic Tests Nest Add', () => {
189
194
const tree = await runner
190
195
. runSchematicAsync ( 'nest-add' , options , nestTree )
191
196
. toPromise ( ) ;
192
- const fileContent = getFileContent ( tree , '/libs/lib1/src/main.azure.ts' ) ;
197
+ const fileContent = getFileContent (
198
+ tree ,
199
+ `/apps/${ projectName } /src/main.azure.ts`
200
+ ) ;
193
201
194
202
expect ( fileContent ) . toContain ( `import { AppModule } from './app.module';` ) ;
195
203
} ) ;
@@ -212,20 +220,20 @@ describe('Schematic Tests Nest Add', () => {
212
220
expect ( fileContent ) . toContain ( `import { AppModule } from './app.module';` ) ;
213
221
} ) ;
214
222
215
- it ( 'should have the root dir for index file in main azure dir for project' , async ( ) => {
223
+ it ( 'should have the root dir for index file in main azure dir for monorepo app' , async ( ) => {
224
+ const projectName = 'azure-2' ;
216
225
const options : Schema = {
217
- sourceRoot : '/libs/lib1/src' ,
218
226
skipInstall : true ,
219
- rootDir : 'src' ,
220
- project : 'lib1'
227
+ project : projectName ,
228
+ sourceRoot : `apps/ ${ projectName } /src`
221
229
} ;
230
+
222
231
await runner
223
232
. runExternalSchematicAsync (
224
233
'@nestjs/schematics' ,
225
- 'library ' ,
234
+ 'sub-app ' ,
226
235
{
227
- name : 'lib1' ,
228
- prefix : '@app'
236
+ name : projectName
229
237
} ,
230
238
nestTree
231
239
)
@@ -234,7 +242,10 @@ describe('Schematic Tests Nest Add', () => {
234
242
const tree = await runner
235
243
. runSchematicAsync ( 'nest-add' , options , nestTree )
236
244
. toPromise ( ) ;
237
- const fileContent = getFileContent ( tree , '/libs/lib1/src/main/index.ts' ) ;
245
+ const fileContent = getFileContent (
246
+ tree ,
247
+ `/apps/${ projectName } /src/main/index.ts`
248
+ ) ;
238
249
239
250
expect ( fileContent ) . toContain ( `import { createApp } from '../main.azure';` ) ;
240
251
} ) ;
@@ -259,34 +270,35 @@ describe('Schematic Tests Nest Add', () => {
259
270
) ;
260
271
} ) ;
261
272
262
- it ( 'should import the webpack config for a project' , async ( ) => {
273
+ it ( 'should import the webpack config for monorepo app' , async ( ) => {
274
+ const projectName = 'azure-2' ;
263
275
const options : Schema = {
264
- sourceRoot : '/libs/lib1/src' ,
265
276
skipInstall : true ,
266
- rootDir : 'src' ,
267
- project : 'lib1'
277
+ project : projectName ,
278
+ sourceRoot : `apps/ ${ projectName } /src`
268
279
} ;
280
+
269
281
await runner
270
282
. runExternalSchematicAsync (
271
283
'@nestjs/schematics' ,
272
- 'library ' ,
284
+ 'sub-app ' ,
273
285
{
274
- name : 'lib1' ,
275
- prefix : '@app'
286
+ name : projectName
276
287
} ,
277
288
nestTree
278
289
)
279
290
. toPromise ( ) ;
280
-
281
291
const tree = await runner
282
292
. runSchematicAsync ( 'nest-add' , options , nestTree )
283
293
. toPromise ( ) ;
284
294
285
295
const fileContent = getFileContent (
286
296
tree ,
287
- '/libs/lib1/src/webpack.config.js'
297
+ `/apps/${ projectName } /src/webpack.config.js`
298
+ ) ;
299
+ expect ( fileContent ) . toContain (
300
+ `filename: 'apps/${ projectName } /main/index.js'`
288
301
) ;
289
- expect ( fileContent ) . toContain ( `filename: 'apps/lib1/main/index.js'` ) ;
290
302
} ) ;
291
303
292
304
it ( 'should not import the webpack config for a default app' , async ( ) => {
@@ -307,48 +319,35 @@ describe('Schematic Tests Nest Add', () => {
307
319
expect ( fileContent ) . toBeNull ( ) ;
308
320
} ) ;
309
321
310
- it ( 'should add a custom webpack config to the compilerOptions for a project' , async ( ) => {
322
+ it ( 'should add a custom webpack config to the compilerOptions for monorepo app' , async ( ) => {
323
+ const projectName = 'azure-2' ;
311
324
const options : Schema = {
312
- sourceRoot : '/apps/azure-func-http/src' ,
313
325
skipInstall : true ,
314
- rootDir : '' ,
315
- project : 'azure-func-http'
326
+ project : projectName ,
327
+ sourceRoot : `apps/ ${ projectName } /src`
316
328
} ;
317
- // await runner
318
- // .runExternalSchematicAsync(
319
- // '@nestjs/schematics',
320
- // 'application',
321
- // {
322
- // name: 'azure-func-http',
323
- // prefix: '@app'
324
- // },
325
- // nestTree
326
- // )
327
- // .toPromise();
328
329
329
330
await runner
330
331
. runExternalSchematicAsync (
331
332
'@nestjs/schematics' ,
332
333
'sub-app' ,
333
334
{
334
- name : 'azure-func-http'
335
+ name : projectName
335
336
} ,
336
337
nestTree
337
338
)
338
339
. toPromise ( ) ;
339
-
340
340
const tree = await runner
341
341
. runSchematicAsync ( 'nest-add' , options , nestTree )
342
342
. toPromise ( ) ;
343
343
344
344
const fileContent = getFileContent ( tree , 'nest-cli.json' ) ;
345
345
const parsedFile = JSON . parse ( fileContent ) ;
346
-
347
- const compilerOptions = parsedFile . projects . lib1 . compilerOptions ;
348
- expect ( compilerOptions ) . toContain ( {
349
- webpack : 'true' ,
350
- webpackConfigPath : 'apps/lib1/src/webpack.config.js' ,
351
- tsConfigPath : 'libs/lib1/tsconfig.lib.json'
346
+ const compilerOptions = parsedFile . projects [ projectName ] . compilerOptions ;
347
+ expect ( compilerOptions ) . toEqual ( {
348
+ tsConfigPath : `apps/${ projectName } /tsconfig.app.json` ,
349
+ webpack : true ,
350
+ webpackConfigPath : `apps/${ projectName } /src/webpack.config.js`
352
351
} ) ;
353
352
} ) ;
354
353
0 commit comments