@@ -2,6 +2,8 @@ import { basename, join } from 'path';
2
2
import * as fs from 'fs' ;
3
3
import * as Constants from '../util/constants' ;
4
4
import * as helpers from '../util/helpers' ;
5
+ import * as globUtils from '../util/glob-util' ;
6
+ import { GlobResult } from '../util/glob-util' ;
5
7
import * as util from './util' ;
6
8
import * as GeneratorConstants from './constants' ;
7
9
@@ -299,13 +301,7 @@ export class $CLASSNAMEModule {}
299
301
const providersDir = '/path/to/providers' ;
300
302
301
303
beforeEach ( ( ) => {
302
- context = {
303
- componentsDir,
304
- directivesDir,
305
- pagesDir,
306
- pipesDir,
307
- providersDir,
308
- } ;
304
+ context = { componentsDir, directivesDir, pagesDir, pipesDir, providersDir } ;
309
305
} ) ;
310
306
311
307
it ( 'should return the appropriate components directory' , ( ) => {
@@ -332,4 +328,43 @@ export class $CLASSNAMEModule {}
332
328
expect ( ( ) => util . getDirToWriteToByType ( context , 'dan' ) ) . toThrowError ( 'Unknown Generator Type: dan' ) ;
333
329
} ) ;
334
330
} ) ;
331
+
332
+ describe ( 'getNgModules' , ( ) => {
333
+ let context : any ;
334
+ const componentsDir = '/path/to/components' ;
335
+ const directivesDir = '/path/to/directives' ;
336
+ const pagesDir = '/path/to/pages' ;
337
+ const pipesDir = '/path/to/pipes' ;
338
+ const providersDir = '/path/to/providers' ;
339
+
340
+ beforeEach ( ( ) => {
341
+ context = { componentsDir, directivesDir, pagesDir, pipesDir, providersDir } ;
342
+ } ) ;
343
+
344
+ function genMockGlobResults ( types : string [ ] ) : GlobResult [ ] {
345
+ return types . map ( ( type ) => {
346
+ return { absolutePath : `/path/to/${ type } ` , base : '/path' }
347
+ } ) ;
348
+ }
349
+
350
+ it ( 'should return an empty list of glob results' , ( ) => {
351
+ const globAllSpy = spyOn ( globUtils , globUtils . globAll . name ) ;
352
+ util . getNgModules ( context , [ ] ) ;
353
+ expect ( globAllSpy ) . toHaveBeenCalledWith ( [ ] ) ;
354
+ } ) ;
355
+
356
+ it ( 'should return a list of glob results for components' , ( ) => {
357
+ const globAllSpy = spyOn ( globUtils , globUtils . globAll . name ) ;
358
+ spyOn ( helpers , helpers . getStringPropertyValue . name ) . and . returnValue ( '.module.ts' ) ;
359
+ util . getNgModules ( context , [ 'component' ] ) ;
360
+ expect ( globAllSpy ) . toHaveBeenCalledWith ( [ '/path/to/components/**/*.module.ts' ] ) ;
361
+ } ) ;
362
+
363
+ it ( 'should return a list of glob results for pages and components' , ( ) => {
364
+ const globAllSpy = spyOn ( globUtils , globUtils . globAll . name ) ;
365
+ spyOn ( helpers , helpers . getStringPropertyValue . name ) . and . returnValue ( '.module.ts' ) ;
366
+ util . getNgModules ( context , [ 'page' , 'component' ] ) ;
367
+ expect ( globAllSpy ) . toHaveBeenCalledWith ( [ '/path/to/pages/**/*.module.ts' , '/path/to/components/**/*.module.ts' ] ) ;
368
+ } ) ;
369
+ } ) ;
335
370
} ) ;
0 commit comments