@@ -16,6 +16,10 @@ describe('Get Dependent Files: ', () => {
16
16
'foo' : {
17
17
'foo.component.ts' : `import * from '../bar/baz/baz.component'
18
18
import * from '../bar/bar.component'` ,
19
+ 'foo.component.html' : '' ,
20
+ 'foo.component.css' : '' ,
21
+ 'foo.component.spec.ts' : '' ,
22
+ 'foo.ts' : '' ,
19
23
'index.ts' : `export * from './foo.component'`
20
24
} ,
21
25
'bar' : {
@@ -24,12 +28,23 @@ describe('Get Dependent Files: ', () => {
24
28
'baz.html' : '<h1> Hello </h1>'
25
29
} ,
26
30
'bar.component.ts' : `import * from './baz/baz.component'
27
- import * from '../foo'`
31
+ import * from '../foo'` ,
32
+ 'bar.component.spec.ts' : ''
28
33
} ,
29
34
'foo-baz' : {
30
- 'no-module.component.ts' : ''
35
+ 'no-module.component.ts' : '' ,
36
+ 'no-module.component.spec.ts' : 'import * from "../bar/bar.component";'
31
37
} ,
32
- 'empty-dir' : { }
38
+ 'quux' : {
39
+ 'quux.ts' : '' ,
40
+ 'quux.html' : '' ,
41
+ 'quux.css' : '' ,
42
+ 'quux.spec.ts' : ''
43
+ } ,
44
+ 'noAngular.tag.ts' : '' ,
45
+ 'noAngular.tag.html' : '' ,
46
+ 'noAngular.tag.sass' : '' ,
47
+ 'noAngular.tag.spec.ts' : '' ,
33
48
}
34
49
} ;
35
50
mockFs ( mockDrive ) ;
@@ -102,13 +117,56 @@ describe('Get Dependent Files: ', () => {
102
117
} ) ;
103
118
} ) ;
104
119
120
+ describe ( 'returns an array of all the associated files of a given component unit.' , ( ) => {
121
+ it ( 'when the component name has a special Angular tag(component/pipe/service)' , ( ) => {
122
+ let sourceFile = path . join ( rootPath , 'foo/foo.component.ts' ) ;
123
+ return dependentFilesUtils . getAllAssociatedFiles ( sourceFile )
124
+ . then ( ( files : string [ ] ) => {
125
+ let expectedContents = [
126
+ 'src/app/foo/foo.component.css' ,
127
+ 'src/app/foo/foo.component.html' ,
128
+ 'src/app/foo/foo.component.spec.ts' ,
129
+ 'src/app/foo/foo.component.ts'
130
+ ] ;
131
+ assert . deepEqual ( files , expectedContents ) ;
132
+ } ) ;
133
+ } ) ;
134
+ it ( 'when the component name has non-Angular tag' , ( ) => {
135
+ let sourceFile = path . join ( rootPath , 'noAngular.tag.ts' ) ;
136
+ return dependentFilesUtils . getAllAssociatedFiles ( sourceFile )
137
+ . then ( ( files : string [ ] ) => {
138
+ let expectedContents = [
139
+ 'src/app/noAngular.tag.html' ,
140
+ 'src/app/noAngular.tag.sass' ,
141
+ 'src/app/noAngular.tag.spec.ts' ,
142
+ 'src/app/noAngular.tag.ts'
143
+ ] ;
144
+ assert . deepEqual ( files , expectedContents ) ;
145
+ } ) ;
146
+ } ) ;
147
+ it ( 'when the component name has no tag after the unique file name' , ( ) => {
148
+ let sourceFile = path . join ( rootPath , 'quux/quux.ts' ) ;
149
+ return dependentFilesUtils . getAllAssociatedFiles ( sourceFile )
150
+ . then ( ( files : string [ ] ) => {
151
+ let expectedContents = [
152
+ 'src/app/quux/quux.css' ,
153
+ 'src/app/quux/quux.html' ,
154
+ 'src/app/quux/quux.spec.ts' ,
155
+ 'src/app/quux/quux.ts'
156
+ ] ;
157
+ assert . deepEqual ( files , expectedContents ) ;
158
+ } ) ;
159
+ } ) ;
160
+ } ) ;
161
+
105
162
describe ( 'returns a map of all files which depend on a given file ' , ( ) => {
106
163
it ( 'when the given component unit has no index file' , ( ) => {
107
164
let sourceFile = path . join ( rootPath , 'bar/bar.component.ts' ) ;
108
165
return dependentFilesUtils . getDependentFiles ( sourceFile , rootPath )
109
166
. then ( ( contents : dependentFilesUtils . ModuleMap ) => {
110
167
let bazFile = path . join ( rootPath , 'bar/baz/baz.component.ts' ) ;
111
168
let fooFile = path . join ( rootPath , 'foo/foo.component.ts' ) ;
169
+ let noModuleSpecFile = path . join ( rootPath , 'foo-baz/no-module.component.spec.ts' ) ;
112
170
let expectedContents : dependentFilesUtils . ModuleMap = { } ;
113
171
expectedContents [ bazFile ] = [ {
114
172
specifierText : '../bar.component' ,
@@ -120,6 +178,11 @@ describe('Get Dependent Files: ', () => {
120
178
pos : 85 ,
121
179
end : 108
122
180
} ] ;
181
+ expectedContents [ noModuleSpecFile ] = [ {
182
+ specifierText : '../bar/bar.component' ,
183
+ pos : 13 ,
184
+ end : 36
185
+ } ] ;
123
186
assert . deepEqual ( contents , expectedContents ) ;
124
187
} ) ;
125
188
} ) ;
0 commit comments