@@ -142,41 +142,41 @@ describe('fileUtils', () => {
142142 }
143143 } ) ;
144144
145- it ( 'should return false for an empty file' , ( ) => {
145+ it ( 'should return false for an empty file' , async ( ) => {
146146 actualNodeFs . writeFileSync ( filePathForBinaryTest , '' ) ;
147- expect ( isBinaryFile ( filePathForBinaryTest ) ) . toBe ( false ) ;
147+ expect ( await isBinaryFile ( filePathForBinaryTest ) ) . toBe ( false ) ;
148148 } ) ;
149149
150- it ( 'should return false for a typical text file' , ( ) => {
150+ it ( 'should return false for a typical text file' , async ( ) => {
151151 actualNodeFs . writeFileSync (
152152 filePathForBinaryTest ,
153153 'Hello, world!\nThis is a test file with normal text content.' ,
154154 ) ;
155- expect ( isBinaryFile ( filePathForBinaryTest ) ) . toBe ( false ) ;
155+ expect ( await isBinaryFile ( filePathForBinaryTest ) ) . toBe ( false ) ;
156156 } ) ;
157157
158- it ( 'should return true for a file with many null bytes' , ( ) => {
158+ it ( 'should return true for a file with many null bytes' , async ( ) => {
159159 const binaryContent = Buffer . from ( [
160160 0x48 , 0x65 , 0x00 , 0x6c , 0x6f , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
161161 ] ) ; // "He\0llo\0\0\0\0\0"
162162 actualNodeFs . writeFileSync ( filePathForBinaryTest , binaryContent ) ;
163- expect ( isBinaryFile ( filePathForBinaryTest ) ) . toBe ( true ) ;
163+ expect ( await isBinaryFile ( filePathForBinaryTest ) ) . toBe ( true ) ;
164164 } ) ;
165165
166- it ( 'should return true for a file with high percentage of non-printable ASCII' , ( ) => {
166+ it ( 'should return true for a file with high percentage of non-printable ASCII' , async ( ) => {
167167 const binaryContent = Buffer . from ( [
168168 0x41 , 0x42 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x43 , 0x44 , 0x06 ,
169169 ] ) ; // AB\x01\x02\x03\x04\x05CD\x06
170170 actualNodeFs . writeFileSync ( filePathForBinaryTest , binaryContent ) ;
171- expect ( isBinaryFile ( filePathForBinaryTest ) ) . toBe ( true ) ;
171+ expect ( await isBinaryFile ( filePathForBinaryTest ) ) . toBe ( true ) ;
172172 } ) ;
173173
174- it ( 'should return false if file access fails (e.g., ENOENT)' , ( ) => {
174+ it ( 'should return false if file access fails (e.g., ENOENT)' , async ( ) => {
175175 // Ensure the file does not exist
176176 if ( actualNodeFs . existsSync ( filePathForBinaryTest ) ) {
177177 actualNodeFs . unlinkSync ( filePathForBinaryTest ) ;
178178 }
179- expect ( isBinaryFile ( filePathForBinaryTest ) ) . toBe ( false ) ;
179+ expect ( await isBinaryFile ( filePathForBinaryTest ) ) . toBe ( false ) ;
180180 } ) ;
181181 } ) ;
182182
@@ -196,64 +196,64 @@ describe('fileUtils', () => {
196196 vi . restoreAllMocks ( ) ; // Restore spies on actualNodeFs
197197 } ) ;
198198
199- it ( 'should detect typescript type by extension (ts)' , ( ) => {
200- expect ( detectFileType ( 'file.ts' ) ) . toBe ( 'text' ) ;
201- expect ( detectFileType ( 'file.test.ts' ) ) . toBe ( 'text' ) ;
199+ it ( 'should detect typescript type by extension (ts)' , async ( ) => {
200+ expect ( await detectFileType ( 'file.ts' ) ) . toBe ( 'text' ) ;
201+ expect ( await detectFileType ( 'file.test.ts' ) ) . toBe ( 'text' ) ;
202202 } ) ;
203203
204- it ( 'should detect image type by extension (png)' , ( ) => {
204+ it ( 'should detect image type by extension (png)' , async ( ) => {
205205 mockMimeLookup . mockReturnValueOnce ( 'image/png' ) ;
206- expect ( detectFileType ( 'file.png' ) ) . toBe ( 'image' ) ;
206+ expect ( await detectFileType ( 'file.png' ) ) . toBe ( 'image' ) ;
207207 } ) ;
208208
209- it ( 'should detect image type by extension (jpeg)' , ( ) => {
209+ it ( 'should detect image type by extension (jpeg)' , async ( ) => {
210210 mockMimeLookup . mockReturnValueOnce ( 'image/jpeg' ) ;
211- expect ( detectFileType ( 'file.jpg' ) ) . toBe ( 'image' ) ;
211+ expect ( await detectFileType ( 'file.jpg' ) ) . toBe ( 'image' ) ;
212212 } ) ;
213213
214- it ( 'should detect svg type by extension' , ( ) => {
215- expect ( detectFileType ( 'image.svg' ) ) . toBe ( 'svg' ) ;
216- expect ( detectFileType ( 'image.icon.svg' ) ) . toBe ( 'svg' ) ;
214+ it ( 'should detect svg type by extension' , async ( ) => {
215+ expect ( await detectFileType ( 'image.svg' ) ) . toBe ( 'svg' ) ;
216+ expect ( await detectFileType ( 'image.icon.svg' ) ) . toBe ( 'svg' ) ;
217217 } ) ;
218218
219- it ( 'should detect pdf type by extension' , ( ) => {
219+ it ( 'should detect pdf type by extension' , async ( ) => {
220220 mockMimeLookup . mockReturnValueOnce ( 'application/pdf' ) ;
221- expect ( detectFileType ( 'file.pdf' ) ) . toBe ( 'pdf' ) ;
221+ expect ( await detectFileType ( 'file.pdf' ) ) . toBe ( 'pdf' ) ;
222222 } ) ;
223223
224- it ( 'should detect audio type by extension' , ( ) => {
224+ it ( 'should detect audio type by extension' , async ( ) => {
225225 mockMimeLookup . mockReturnValueOnce ( 'audio/mpeg' ) ;
226- expect ( detectFileType ( 'song.mp3' ) ) . toBe ( 'audio' ) ;
226+ expect ( await detectFileType ( 'song.mp3' ) ) . toBe ( 'audio' ) ;
227227 } ) ;
228228
229- it ( 'should detect video type by extension' , ( ) => {
229+ it ( 'should detect video type by extension' , async ( ) => {
230230 mockMimeLookup . mockReturnValueOnce ( 'video/mp4' ) ;
231- expect ( detectFileType ( 'movie.mp4' ) ) . toBe ( 'video' ) ;
231+ expect ( await detectFileType ( 'movie.mp4' ) ) . toBe ( 'video' ) ;
232232 } ) ;
233233
234- it ( 'should detect known binary extensions as binary (e.g. .zip)' , ( ) => {
234+ it ( 'should detect known binary extensions as binary (e.g. .zip)' , async ( ) => {
235235 mockMimeLookup . mockReturnValueOnce ( 'application/zip' ) ;
236- expect ( detectFileType ( 'archive.zip' ) ) . toBe ( 'binary' ) ;
236+ expect ( await detectFileType ( 'archive.zip' ) ) . toBe ( 'binary' ) ;
237237 } ) ;
238- it ( 'should detect known binary extensions as binary (e.g. .exe)' , ( ) => {
238+ it ( 'should detect known binary extensions as binary (e.g. .exe)' , async ( ) => {
239239 mockMimeLookup . mockReturnValueOnce ( 'application/octet-stream' ) ; // Common for .exe
240- expect ( detectFileType ( 'app.exe' ) ) . toBe ( 'binary' ) ;
240+ expect ( await detectFileType ( 'app.exe' ) ) . toBe ( 'binary' ) ;
241241 } ) ;
242242
243- it ( 'should use isBinaryFile for unknown extensions and detect as binary' , ( ) => {
243+ it ( 'should use isBinaryFile for unknown extensions and detect as binary' , async ( ) => {
244244 mockMimeLookup . mockReturnValueOnce ( false ) ; // Unknown mime type
245245 // Create a file that isBinaryFile will identify as binary
246246 const binaryContent = Buffer . from ( [
247247 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a ,
248248 ] ) ;
249249 actualNodeFs . writeFileSync ( filePathForDetectTest , binaryContent ) ;
250- expect ( detectFileType ( filePathForDetectTest ) ) . toBe ( 'binary' ) ;
250+ expect ( await detectFileType ( filePathForDetectTest ) ) . toBe ( 'binary' ) ;
251251 } ) ;
252252
253- it ( 'should default to text if mime type is unknown and content is not binary' , ( ) => {
253+ it ( 'should default to text if mime type is unknown and content is not binary' , async ( ) => {
254254 mockMimeLookup . mockReturnValueOnce ( false ) ; // Unknown mime type
255255 // filePathForDetectTest is already a text file by default from beforeEach
256- expect ( detectFileType ( filePathForDetectTest ) ) . toBe ( 'text' ) ;
256+ expect ( await detectFileType ( filePathForDetectTest ) ) . toBe ( 'text' ) ;
257257 } ) ;
258258 } ) ;
259259
0 commit comments