@@ -74,6 +74,25 @@ describe('find-module', () => {
74
74
expect ( err . message ) . toMatch ( / C o u l d n o t f i n d a n N g M o d u l e / ) ;
75
75
}
76
76
} ) ;
77
+
78
+ it ( 'should accept custom ext for module' , ( ) => {
79
+ const host = new EmptyTree ( ) ;
80
+ const modulePath = '/foo/src/app/app_module.ts' ;
81
+ host . create ( modulePath , 'app module' ) ;
82
+ // Should find module if given a custom ext
83
+ const foundModule = findModule ( host , 'foo/src/app/bar' , '_module.ts' ) ;
84
+ expect ( foundModule ) . toBe ( modulePath ) ;
85
+ // Should not find module if using default ext
86
+ expect ( ( ) => findModule ( host , 'foo/src/app/bar' ) )
87
+ . toThrowError ( / C o u l d n o t f i n d a n N g M o d u l e / ) ;
88
+ } ) ;
89
+
90
+ it ( 'should not find module if ext is invalid' , ( ) => {
91
+ expect ( ( ) => findModule ( host , 'foo/src/app/bar' , '-module.ts' ) )
92
+ . toThrowError ( / C o u l d n o t f i n d a n N g M o d u l e / ) ;
93
+ expect ( ( ) => findModule ( host , 'foo/src/app/bar' , '_module.ts' ) )
94
+ . toThrowError ( / C o u l d n o t f i n d a n N g M o d u l e / ) ;
95
+ } ) ;
77
96
} ) ;
78
97
79
98
describe ( 'findModuleFromOptions' , ( ) => {
@@ -100,5 +119,40 @@ describe('find-module', () => {
100
119
const modPath = findModuleFromOptions ( tree , options ) ;
101
120
expect ( modPath ) . toEqual ( '/projects/my-proj/src/admin/foo.module.ts' as Path ) ;
102
121
} ) ;
122
+
123
+ it ( 'should find a module using custom ext' , ( ) => {
124
+ tree . create ( '/projects/my-proj/src/app_module.ts' , '' ) ;
125
+ options . module = 'app' ;
126
+ options . path = '/projects/my-proj/src' ;
127
+ options . moduleExt = '_module.ts' ;
128
+ // Should find module using custom moduleExt
129
+ const modPath = findModuleFromOptions ( tree , options ) ;
130
+ expect ( modPath ) . toBe ( '/projects/my-proj/src/app_module.ts' as Path ) ;
131
+ // Should not find module if using invalid ext
132
+ options . moduleExt = '-module.ts' ;
133
+ expect ( ( ) => findModuleFromOptions ( tree , options ) ) . toThrowError (
134
+ / S p e c i f i e d m o d u l e ' a p p ' d o e s n o t e x i s t / ) ;
135
+ // Should not find module if using default ext
136
+ options . moduleExt = undefined ; // use default ext
137
+ expect ( ( ) => findModuleFromOptions ( tree , options ) ) . toThrowError (
138
+ / S p e c i f i e d m o d u l e ' a p p ' d o e s n o t e x i s t / ) ;
139
+ } ) ;
140
+
141
+ it ( 'should ignore custom ext if module or ${module}.ts exists' , ( ) => {
142
+ tree . create ( '/projects/my-proj/src/app.module.ts' , '' ) ;
143
+ options . path = '/projects/my-proj/src' ;
144
+ options . moduleExt = '_module.ts' ;
145
+ let modPath ;
146
+
147
+ // moduleExt ignored because exact path is found
148
+ options . module = 'app.module.ts' ;
149
+ modPath = findModuleFromOptions ( tree , options ) ;
150
+ expect ( modPath ) . toBe ( '/projects/my-proj/src/app.module.ts' as Path ) ;
151
+
152
+ // moduleExt ignored because module + .ts is found
153
+ options . module = 'app.module' ;
154
+ modPath = findModuleFromOptions ( tree , options ) ;
155
+ expect ( modPath ) . toBe ( '/projects/my-proj/src/app.module.ts' as Path ) ;
156
+ } ) ;
103
157
} ) ;
104
158
} ) ;
0 commit comments