6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { Path } from '@angular-devkit/core' ;
10
9
import { EmptyTree , Tree } from '@angular-devkit/schematics' ;
11
10
import { ModuleOptions , buildRelativePath , findModule , findModuleFromOptions } from './find-module' ;
12
11
@@ -107,51 +106,51 @@ describe('find-module', () => {
107
106
tree . create ( '/projects/my-proj/src/app.module.ts' , '' ) ;
108
107
options . module = 'app.module.ts' ;
109
108
options . path = '/projects/my-proj/src' ;
110
- const modPath = findModuleFromOptions ( tree , options ) ;
111
- expect ( modPath ) . toEqual ( '/projects/my-proj/src/app.module.ts' as Path ) ;
109
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
110
+ expect ( modPath ) . toEqual ( '/projects/my-proj/src/app.module.ts' ) ;
112
111
} ) ;
113
112
114
113
it ( 'should find a module when name has underscore' , ( ) => {
115
114
tree . create ( '/projects/my-proj/src/feature_module/app_test.module.ts' , '' ) ;
116
115
options . path = '/projects/my-proj/src' ;
117
116
options . name = 'feature_module/new_component' ;
118
- const modPath = findModuleFromOptions ( tree , options ) ;
119
- expect ( modPath ) . toEqual ( '/projects/my-proj/src/feature_module/app_test.module.ts' as Path ) ;
117
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
118
+ expect ( modPath ) . toEqual ( '/projects/my-proj/src/feature_module/app_test.module.ts' ) ;
120
119
} ) ;
121
120
122
121
it ( 'should find a module when name has uppercase' , ( ) => {
123
122
tree . create ( '/projects/my-proj/src/featureModule/appTest.module.ts' , '' ) ;
124
123
options . path = '/projects/my-proj/src' ;
125
124
options . name = 'featureModule/newComponent' ;
126
- const modPath = findModuleFromOptions ( tree , options ) ;
127
- expect ( modPath ) . toEqual ( '/projects/my-proj/src/featureModule/appTest.module.ts' as Path ) ;
125
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
126
+ expect ( modPath ) . toEqual ( '/projects/my-proj/src/featureModule/appTest.module.ts' ) ;
128
127
} ) ;
129
128
130
129
it ( 'should find a module if flat is true' , ( ) => {
131
130
tree . create ( '/projects/my-proj/src/module/app_test.module.ts' , '' ) ;
132
131
options . path = '/projects/my-proj/src' ;
133
132
options . flat = true ;
134
133
options . name = '/module/directive' ;
135
- const modPath = findModuleFromOptions ( tree , options ) ;
136
- expect ( modPath ) . toEqual ( '/projects/my-proj/src/module/app_test.module.ts' as Path ) ;
134
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
135
+ expect ( modPath ) . toEqual ( '/projects/my-proj/src/module/app_test.module.ts' ) ;
137
136
} ) ;
138
137
139
138
it ( 'should find a module in a sub dir' , ( ) => {
140
139
tree . create ( '/projects/my-proj/src/admin/foo.module.ts' , '' ) ;
141
140
options . name = 'other/test' ;
142
141
options . module = 'admin/foo' ;
143
142
options . path = '/projects/my-proj/src' ;
144
- const modPath = findModuleFromOptions ( tree , options ) ;
145
- expect ( modPath ) . toEqual ( '/projects/my-proj/src/admin/foo.module.ts' as Path ) ;
143
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
144
+ expect ( modPath ) . toEqual ( '/projects/my-proj/src/admin/foo.module.ts' ) ;
146
145
} ) ;
147
146
148
147
it ( 'should find a module in a sub dir (2)' , ( ) => {
149
148
tree . create ( '/projects/my-proj/src/admin/foo.module.ts' , '' ) ;
150
149
options . name = 'admin/hello' ;
151
150
options . module = 'foo' ;
152
151
options . path = '/projects/my-proj/src' ;
153
- const modPath = findModuleFromOptions ( tree , options ) ;
154
- expect ( modPath ) . toEqual ( '/projects/my-proj/src/admin/foo.module.ts' as Path ) ;
152
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
153
+ expect ( modPath ) . toEqual ( '/projects/my-proj/src/admin/foo.module.ts' ) ;
155
154
} ) ;
156
155
157
156
it ( 'should find a module using custom ext' , ( ) => {
@@ -160,16 +159,16 @@ describe('find-module', () => {
160
159
options . path = '/projects/my-proj/src' ;
161
160
options . moduleExt = '_module.ts' ;
162
161
// Should find module using custom moduleExt
163
- const modPath = findModuleFromOptions ( tree , options ) ;
164
- expect ( modPath ) . toBe ( '/projects/my-proj/src/app_module.ts' as Path ) ;
162
+ const modPath = findModuleFromOptions ( tree , options ) as string ;
163
+ expect ( modPath ) . toBe ( '/projects/my-proj/src/app_module.ts' ) ;
165
164
// Should not find module if using invalid ext
166
165
options . moduleExt = '-module.ts' ;
167
- expect ( ( ) => findModuleFromOptions ( tree , options ) ) . toThrowError (
166
+ expect ( ( ) => findModuleFromOptions ( tree , options ) as string ) . toThrowError (
168
167
/ 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 / ,
169
168
) ;
170
169
// Should not find module if using default ext
171
170
options . moduleExt = undefined ; // use default ext
172
- expect ( ( ) => findModuleFromOptions ( tree , options ) ) . toThrowError (
171
+ expect ( ( ) => findModuleFromOptions ( tree , options ) as string ) . toThrowError (
173
172
/ 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 / ,
174
173
) ;
175
174
} ) ;
@@ -182,13 +181,13 @@ describe('find-module', () => {
182
181
183
182
// moduleExt ignored because exact path is found
184
183
options . module = 'app.module.ts' ;
185
- modPath = findModuleFromOptions ( tree , options ) ;
186
- expect ( modPath ) . toBe ( '/projects/my-proj/src/app.module.ts' as Path ) ;
184
+ modPath = findModuleFromOptions ( tree , options ) as string ;
185
+ expect ( modPath ) . toBe ( '/projects/my-proj/src/app.module.ts' ) ;
187
186
188
187
// moduleExt ignored because module + .ts is found
189
188
options . module = 'app.module' ;
190
- modPath = findModuleFromOptions ( tree , options ) ;
191
- expect ( modPath ) . toBe ( '/projects/my-proj/src/app.module.ts' as Path ) ;
189
+ modPath = findModuleFromOptions ( tree , options ) as string ;
190
+ expect ( modPath ) . toBe ( '/projects/my-proj/src/app.module.ts' ) ;
192
191
} ) ;
193
192
} ) ;
194
193
0 commit comments