@@ -16,6 +16,10 @@ describe('Get Dependent Files: ', () => {
1616 'foo' : {
1717 'foo.component.ts' : `import * from '../bar/baz/baz.component'
1818 import * from '../bar/bar.component'` ,
19+ 'foo.component.html' : '' ,
20+ 'foo.component.css' : '' ,
21+ 'foo.component.spec.ts' : '' ,
22+ 'foo.ts' : '' ,
1923 'index.ts' : `export * from './foo.component'`
2024 } ,
2125 'bar' : {
@@ -24,12 +28,23 @@ describe('Get Dependent Files: ', () => {
2428 'baz.html' : '<h1> Hello </h1>'
2529 } ,
2630 'bar.component.ts' : `import * from './baz/baz.component'
27- import * from '../foo'`
31+ import * from '../foo'` ,
32+ 'bar.component.spec.ts' : ''
2833 } ,
2934 'foo-baz' : {
30- 'no-module.component.ts' : ''
35+ 'no-module.component.ts' : '' ,
36+ 'no-module.component.spec.ts' : 'import * from "../bar/bar.component";'
3137 } ,
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' : '' ,
3348 }
3449 } ;
3550 mockFs ( mockDrive ) ;
@@ -102,13 +117,56 @@ describe('Get Dependent Files: ', () => {
102117 } ) ;
103118 } ) ;
104119
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+
105162 describe ( 'returns a map of all files which depend on a given file ' , ( ) => {
106163 it ( 'when the given component unit has no index file' , ( ) => {
107164 let sourceFile = path . join ( rootPath , 'bar/bar.component.ts' ) ;
108165 return dependentFilesUtils . getDependentFiles ( sourceFile , rootPath )
109166 . then ( ( contents : dependentFilesUtils . ModuleMap ) => {
110167 let bazFile = path . join ( rootPath , 'bar/baz/baz.component.ts' ) ;
111168 let fooFile = path . join ( rootPath , 'foo/foo.component.ts' ) ;
169+ let noModuleSpecFile = path . join ( rootPath , 'foo-baz/no-module.component.spec.ts' ) ;
112170 let expectedContents : dependentFilesUtils . ModuleMap = { } ;
113171 expectedContents [ bazFile ] = [ {
114172 specifierText : '../bar.component' ,
@@ -120,6 +178,11 @@ describe('Get Dependent Files: ', () => {
120178 pos : 85 ,
121179 end : 108
122180 } ] ;
181+ expectedContents [ noModuleSpecFile ] = [ {
182+ specifierText : '../bar/bar.component' ,
183+ pos : 13 ,
184+ end : 36
185+ } ] ;
123186 assert . deepEqual ( contents , expectedContents ) ;
124187 } ) ;
125188 } ) ;
0 commit comments