@@ -10,6 +10,30 @@ import { UnitTestRunner } from '../../../utils/test-runners';
10
10
describe ( 'updateModuleName Rule' , ( ) => {
11
11
let tree : Tree ;
12
12
13
+ beforeEach ( ( ) => {
14
+ tree = createTreeWithEmptyWorkspace ( ) ;
15
+ } ) ;
16
+
17
+ it ( 'should handle nesting resulting in the same project name' , async ( ) => {
18
+ const updatedModulePath = '/libs/my/first/src/lib/my-first.module.ts' ;
19
+ await libraryGenerator ( tree , {
20
+ name : 'my-first' ,
21
+ simpleModuleName : true ,
22
+ } ) ;
23
+ const schema : Schema = {
24
+ projectName : 'my-first' ,
25
+ destination : 'my/first' ,
26
+ updateImportPath : true ,
27
+ } ;
28
+ await moveGenerator ( tree , schema ) ;
29
+
30
+ updateModuleName ( tree , { ...schema , destination : 'my/first' } ) ;
31
+
32
+ expect ( tree . exists ( updatedModulePath ) ) . toBe ( true ) ;
33
+ const moduleFile = tree . read ( updatedModulePath ) . toString ( 'utf-8' ) ;
34
+ expect ( moduleFile ) . toContain ( `export class MyFirstModule { }` ) ;
35
+ } ) ;
36
+
13
37
describe ( 'move to subfolder' , ( ) => {
14
38
const updatedModulePath =
15
39
'/libs/shared/my-first/src/lib/shared-my-first.module.ts' ;
@@ -25,8 +49,6 @@ describe('updateModuleName Rule', () => {
25
49
} ;
26
50
27
51
beforeEach ( async ( ) => {
28
- tree = createTreeWithEmptyWorkspace ( ) ;
29
-
30
52
await libraryGenerator ( tree , {
31
53
name : 'my-first' ,
32
54
buildable : false ,
@@ -86,7 +108,7 @@ describe('updateModuleName Rule', () => {
86
108
} ) ;
87
109
88
110
it ( 'should rename the module files and update the module name' , async ( ) => {
89
- await updateModuleName ( tree , schema ) ;
111
+ updateModuleName ( tree , schema ) ;
90
112
91
113
expect ( tree . exists ( updatedModulePath ) ) . toBe ( true ) ;
92
114
expect ( tree . exists ( updatedModuleSpecPath ) ) . toBe ( true ) ;
@@ -108,26 +130,27 @@ describe('updateModuleName Rule', () => {
108
130
} ) ;
109
131
110
132
it ( 'should update any references to the module' , async ( ) => {
111
- await updateModuleName ( tree , schema ) ;
133
+ updateModuleName ( tree , schema ) ;
112
134
113
135
const importerFile = tree . read ( secondModulePath ) . toString ( 'utf-8' ) ;
114
136
expect ( importerFile ) . toContain (
115
- `import { SharedMyFirstModule } from '@proj/shared/ my-first';`
137
+ `import { SharedMyFirstModule } from '@proj/shared- my-first';`
116
138
) ;
117
139
expect ( importerFile ) . toContain (
118
140
`export class MySecondModule extends SharedMyFirstModule {}`
119
141
) ;
120
142
} ) ;
121
143
122
144
it ( 'should update the index.ts file which exports the module' , async ( ) => {
123
- await updateModuleName ( tree , schema ) ;
145
+ updateModuleName ( tree , schema ) ;
124
146
125
147
const indexFile = tree . read ( indexPath ) . toString ( 'utf-8' ) ;
126
148
expect ( indexFile ) . toContain (
127
149
`export * from './lib/shared-my-first.module';`
128
150
) ;
129
151
} ) ;
130
152
} ) ;
153
+
131
154
describe ( 'rename' , ( ) => {
132
155
const schema : Schema = {
133
156
projectName : 'my-source' ,
@@ -142,8 +165,6 @@ describe('updateModuleName Rule', () => {
142
165
const importerPath = '/libs/my-importer/src/lib/my-importing-file.ts' ;
143
166
144
167
beforeEach ( async ( ) => {
145
- tree = createTreeWithEmptyWorkspace ( ) ;
146
-
147
168
// fake a mid-move tree:
148
169
await libraryGenerator ( tree , {
149
170
name : 'my-destination' ,
@@ -211,7 +232,7 @@ describe('updateModuleName Rule', () => {
211
232
} ) ;
212
233
213
234
it ( 'should rename the module files and update the module name' , async ( ) => {
214
- await updateModuleName ( tree , schema ) ;
235
+ updateModuleName ( tree , schema ) ;
215
236
216
237
expect ( tree . exists ( modulePath ) ) . toBe ( true ) ;
217
238
expect ( tree . exists ( moduleSpecPath ) ) . toBe ( true ) ;
@@ -233,7 +254,7 @@ describe('updateModuleName Rule', () => {
233
254
} ) ;
234
255
235
256
it ( 'should update any references to the module' , async ( ) => {
236
- await updateModuleName ( tree , schema ) ;
257
+ updateModuleName ( tree , schema ) ;
237
258
238
259
const importerFile = tree . read ( importerPath ) . toString ( 'utf-8' ) ;
239
260
expect ( importerFile ) . toContain (
@@ -245,7 +266,7 @@ describe('updateModuleName Rule', () => {
245
266
} ) ;
246
267
247
268
it ( 'should update the index.ts file which exports the module' , async ( ) => {
248
- await updateModuleName ( tree , schema ) ;
269
+ updateModuleName ( tree , schema ) ;
249
270
250
271
const indexFile = tree . read ( indexPath ) . toString ( 'utf-8' ) ;
251
272
expect ( indexFile ) . toContain (
0 commit comments