@@ -6,6 +6,7 @@ import should from 'should'; // eslint-disable-line no-unused-vars
6
6
import FileSystemFactory , { FileSystem } from '../src/FileSystem' ;
7
7
import pathLib from 'path' ;
8
8
import { mockData } from './mockData' ;
9
+ import RNFetchBlob from 'rn-fetch-blob' ;
9
10
10
11
describe ( 'FileSystem' , function ( ) {
11
12
// Test static class properties and methods
@@ -69,7 +70,6 @@ describe('FileSystem', function () {
69
70
} ) ;
70
71
71
72
it ( '#exists mocked as true.' , ( ) => {
72
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
73
73
RNFetchBlob . fs . exists . mockReturnValue ( true ) ;
74
74
75
75
const fileSystem = FileSystemFactory ( ) ;
@@ -128,71 +128,63 @@ describe('FileSystem', function () {
128
128
fetch = jest . fn ( ) ; // eslint-disable-line no-global-assign
129
129
130
130
// Test PNG
131
- fetch . mockReturnValueOnce (
132
- Promise . resolve ( {
133
- headers : {
134
- get : ( headerName ) => {
135
- headerName . should . equals ( 'content-type' ) ;
136
-
137
- return 'image/png' ;
138
- } ,
131
+ fetch . mockResolvedValueOnce ( {
132
+ headers : {
133
+ get : ( headerName ) => {
134
+ headerName . should . equals ( 'content-type' ) ;
135
+
136
+ return 'image/png' ;
139
137
} ,
140
- } )
141
- ) ;
138
+ } ,
139
+ } ) ;
142
140
143
141
const pngFilename = await fileSystem . getFileNameFromUrl (
144
142
'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red'
145
143
) ;
146
144
pngFilename . should . equal ( '831eb245a3d9032cdce450f8760d2b8ddb442a3d.png' ) ;
147
145
148
146
// Test JPG
149
- fetch . mockReturnValueOnce (
150
- Promise . resolve ( {
151
- headers : {
152
- get : ( headerName ) => {
153
- headerName . should . equals ( 'content-type' ) ;
154
-
155
- return 'image/jpeg' ;
156
- } ,
147
+ fetch . mockResolvedValueOnce ( {
148
+ headers : {
149
+ get : ( headerName ) => {
150
+ headerName . should . equals ( 'content-type' ) ;
151
+
152
+ return 'image/jpeg' ;
157
153
} ,
158
- } )
159
- ) ;
154
+ } ,
155
+ } ) ;
160
156
161
157
const jpgFilename = await fileSystem . getFileNameFromUrl (
162
158
'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red'
163
159
) ;
164
160
jpgFilename . should . equal ( '831eb245a3d9032cdce450f8760d2b8ddb442a3d.jpg' ) ;
165
161
166
162
// Test GIF
167
- fetch . mockReturnValueOnce (
168
- Promise . resolve ( {
169
- headers : {
170
- get : ( headerName ) => {
171
- headerName . should . equals ( 'content-type' ) ;
172
-
173
- return 'image/gif' ;
174
- } ,
163
+ fetch . mockResolvedValueOnce ( {
164
+ headers : {
165
+ get : ( headerName ) => {
166
+ headerName . should . equals ( 'content-type' ) ;
167
+
168
+ return 'image/gif' ;
175
169
} ,
176
- } )
177
- ) ;
170
+ } ,
171
+ } ) ;
178
172
179
173
const gifFilename = await fileSystem . getFileNameFromUrl (
180
174
'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red'
181
175
) ;
182
176
gifFilename . should . equal ( '831eb245a3d9032cdce450f8760d2b8ddb442a3d.gif' ) ;
183
177
184
178
// Test BMP
185
- fetch . mockReturnValueOnce (
186
- Promise . resolve ( {
187
- headers : {
188
- get : ( headerName ) => {
189
- headerName . should . equals ( 'content-type' ) ;
190
-
191
- return 'image/bmp' ;
192
- } ,
179
+ fetch . mockResolvedValueOnce ( {
180
+ headers : {
181
+ get : ( headerName ) => {
182
+ headerName . should . equals ( 'content-type' ) ;
183
+
184
+ return 'image/bmp' ;
193
185
} ,
194
- } )
195
- ) ;
186
+ } ,
187
+ } ) ;
196
188
197
189
const bmpFilename = await fileSystem . getFileNameFromUrl (
198
190
'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red'
@@ -201,7 +193,6 @@ describe('FileSystem', function () {
201
193
} ) ;
202
194
203
195
it ( '#getLocalFilePathFromUrl should return local filepath if it exists on local fs in permanent dir.' , ( ) => {
204
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
205
196
RNFetchBlob . fs . exists
206
197
. mockReturnValueOnce ( true ) // mock exist in local permanent dir
207
198
. mockReturnValue ( true ) ;
@@ -221,7 +212,6 @@ describe('FileSystem', function () {
221
212
} ) ;
222
213
223
214
it ( '#getLocalFilePathFromUrl should return local filepath if it exists on local fs in cache dir.' , ( ) => {
224
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
225
215
RNFetchBlob . fs . exists
226
216
. mockReturnValueOnce ( false ) // mock not exist in local permanent dir
227
217
. mockReturnValueOnce ( true ) // mock exist in local cache dir
@@ -242,7 +232,6 @@ describe('FileSystem', function () {
242
232
} ) ;
243
233
244
234
it ( '#getLocalFilePathFromUrl should download file and write to disk (default to cache dir) if it does not exist on local fs.' , ( ) => {
245
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
246
235
RNFetchBlob . fs . exists
247
236
. mockReturnValueOnce ( false ) // mock not exist in local permanent dir
248
237
. mockReturnValueOnce ( false ) // mock not exist in local cache dir
@@ -291,7 +280,6 @@ describe('FileSystem', function () {
291
280
it ( '#fetchFile clobber safeguard should work.' , ( ) => {
292
281
const fileSystem = FileSystemFactory ( ) ;
293
282
294
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
295
283
RNFetchBlob . fetch . mockReturnValue ( {
296
284
path : ( ) => {
297
285
return '/this/is/path/to/file.jpg' ;
@@ -320,7 +308,6 @@ describe('FileSystem', function () {
320
308
it ( '#fetchFile prune logic should not be called on permanent writes.' , ( ) => {
321
309
const fileSystem = FileSystemFactory ( ) ;
322
310
323
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
324
311
RNFetchBlob . fetch . mockReturnValue ( {
325
312
path : ( ) => {
326
313
return '/this/is/path/to/file.jpg' ;
@@ -350,7 +337,6 @@ describe('FileSystem', function () {
350
337
it ( '#fetchFile prune logic should be called on cache writes.' , ( ) => {
351
338
const fileSystem = FileSystemFactory ( ) ;
352
339
353
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
354
340
RNFetchBlob . fetch . mockReturnValue ( {
355
341
path : ( ) => {
356
342
return '/this/is/path/to/file.jpg' ;
@@ -380,7 +366,6 @@ describe('FileSystem', function () {
380
366
it ( '#fetchFile should work as expected.' , ( ) => {
381
367
const fileSystem = FileSystemFactory ( ) ;
382
368
383
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
384
369
RNFetchBlob . fetch . mockReturnValue ( {
385
370
path : ( ) => {
386
371
return '/this/is/path/to/file.jpg' ;
@@ -433,7 +418,6 @@ describe('FileSystem', function () {
433
418
434
419
it ( '#unlink should work as expected for valid paths.' , ( ) => {
435
420
// RNFetchBlob Mocks
436
- const RNFetchBlob = require ( 'rn-fetch-blob' ) ;
437
421
438
422
// Mock unlink to be true.
439
423
RNFetchBlob . fs . unlink . mockReturnValueOnce ( true ) ;
0 commit comments