@@ -25,6 +25,28 @@ describe(intakeFile, () => {
25
25
expect ( actual ) . toBeUndefined ( ) ;
26
26
} ) ;
27
27
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
+
28
50
it ( "returns the file when filePath points to a root-level file" , ( ) => {
29
51
const value = "abc123" ;
30
52
@@ -38,6 +60,17 @@ describe(intakeFile, () => {
38
60
expect ( actual ) . toEqual ( [ value ] ) ;
39
61
} ) ;
40
62
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
+
41
74
it ( "returns the file when filePath points to a file in a directory" , ( ) => {
42
75
const value = "abc123" ;
43
76
@@ -52,4 +85,90 @@ describe(intakeFile, () => {
52
85
53
86
expect ( actual ) . toEqual ( [ value ] ) ;
54
87
} ) ;
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
+ } ) ;
55
174
} ) ;
0 commit comments