@@ -25,6 +25,28 @@ describe(intakeFile, () => {
2525 expect ( actual ) . toBeUndefined ( ) ;
2626 } ) ;
2727
28+ it ( "returns undefined when filePath points to a root-level directory" , ( ) => {
29+ const actual = intakeFile (
30+ {
31+ "file.txt" : { } ,
32+ } ,
33+ [ "file.txt" ] ,
34+ ) ;
35+
36+ expect ( actual ) . toBeUndefined ( ) ;
37+ } ) ;
38+
39+ it ( "returns undefined when filePath points to a root-level undefined" , ( ) => {
40+ const actual = intakeFile (
41+ {
42+ "file.txt" : undefined ,
43+ } ,
44+ [ "file.txt" ] ,
45+ ) ;
46+
47+ expect ( actual ) . toBeUndefined ( ) ;
48+ } ) ;
49+
2850 it ( "returns the file when filePath points to a root-level file" , ( ) => {
2951 const value = "abc123" ;
3052
@@ -38,6 +60,17 @@ describe(intakeFile, () => {
3860 expect ( actual ) . toEqual ( [ value ] ) ;
3961 } ) ;
4062
63+ it ( "returns undefined when filePath is within a file" , ( ) => {
64+ const actual = intakeFile (
65+ {
66+ src : [ "abc123" ] ,
67+ } ,
68+ [ "src" , "file.txt" ] ,
69+ ) ;
70+
71+ expect ( actual ) . toBeUndefined ( ) ;
72+ } ) ;
73+
4174 it ( "returns the file when filePath points to a file in a directory" , ( ) => {
4275 const value = "abc123" ;
4376
@@ -52,4 +85,90 @@ describe(intakeFile, () => {
5285
5386 expect ( actual ) . toEqual ( [ value ] ) ;
5487 } ) ;
88+
89+ it ( "returns undefined when filePath points to a directory in a directory" , ( ) => {
90+ const actual = intakeFile (
91+ {
92+ src : {
93+ "file.txt" : { } ,
94+ } ,
95+ } ,
96+ [ "src" , "file.txt" ] ,
97+ ) ;
98+
99+ expect ( actual ) . toBeUndefined ( ) ;
100+ } ) ;
101+
102+ it ( "returns the file when filePath does not point to a file in the root" , ( ) => {
103+ const value = "abc123" ;
104+
105+ const actual = intakeFile (
106+ {
107+ "file.txt" : [ value ] ,
108+ } ,
109+ [ "other.txt" ] ,
110+ ) ;
111+
112+ expect ( actual ) . toBeUndefined ( ) ;
113+ } ) ;
114+
115+ it ( "returns the file when filePath does not point to a file in a directory" , ( ) => {
116+ const value = "abc123" ;
117+
118+ const actual = intakeFile (
119+ {
120+ src : {
121+ "file.txt" : [ value ] ,
122+ } ,
123+ } ,
124+ [ "src" , "other.txt" ] ,
125+ ) ;
126+
127+ expect ( actual ) . toBeUndefined ( ) ;
128+ } ) ;
129+
130+ it ( "returns the file when filePath is an array whose first element points to a file in a directory" , ( ) => {
131+ const value = "abc123" ;
132+
133+ const actual = intakeFile (
134+ {
135+ src : {
136+ "file.txt" : [ value ] ,
137+ } ,
138+ } ,
139+ [ "src" , [ "file.txt" , "other.txt" ] ] ,
140+ ) ;
141+
142+ expect ( actual ) . toEqual ( [ value ] ) ;
143+ } ) ;
144+
145+ it ( "returns the file when filePath is an array whose second element points to a file in a directory" , ( ) => {
146+ const value = "abc123" ;
147+
148+ const actual = intakeFile (
149+ {
150+ src : {
151+ "file.txt" : [ value ] ,
152+ } ,
153+ } ,
154+ [ "src" , [ "other.txt" , "file.txt" ] ] ,
155+ ) ;
156+
157+ expect ( actual ) . toEqual ( [ value ] ) ;
158+ } ) ;
159+
160+ it ( "returns nothing when filePath is an array and no element points to a file in a directory" , ( ) => {
161+ const value = "abc123" ;
162+
163+ const actual = intakeFile (
164+ {
165+ src : {
166+ "file.txt" : [ value ] ,
167+ } ,
168+ } ,
169+ [ "src" , [ "other-a.txt" , "other-b.txt" ] ] ,
170+ ) ;
171+
172+ expect ( actual ) . toBeUndefined ( ) ;
173+ } ) ;
55174} ) ;
0 commit comments