|
@@ -19,26 +19,21 @@ const describe = RNTest.config({
|
19
|
19
|
})
|
20
|
20
|
|
21
|
21
|
let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
|
22
|
|
-let dirs = null
|
|
22
|
+let dirs = RNFetchBlob.fs.dirs
|
23
|
23
|
|
24
|
24
|
describe('Get storage folders', (report, done) => {
|
25
|
|
- fs.getSystemDirs().then((resp) => {
|
26
|
|
- dirs = resp
|
27
|
|
- console.log(dirs)
|
28
|
|
- report(
|
29
|
|
- <Assert key="system folders should exists" expect={resp} comparer={Comparer.exists} />,
|
30
|
|
- <Assert key="check properties"
|
31
|
|
- expect={['DocumentDir', 'CacheDir']}
|
32
|
|
- comparer={Comparer.hasProperties}
|
33
|
|
- actual={dirs}
|
34
|
|
- />,
|
35
|
|
- <Info key="System Folders">
|
36
|
|
- <Text>{`${JSON.stringify(dirs)}`}</Text>
|
37
|
|
- </Info>
|
38
|
|
- )
|
39
|
|
- done()
|
40
|
|
- })
|
41
|
|
-
|
|
25
|
+ report(
|
|
26
|
+ <Assert key="system folders should exists" expect={resp} comparer={Comparer.exists} />,
|
|
27
|
+ <Assert key="check properties"
|
|
28
|
+ expect={['DocumentDir', 'CacheDir']}
|
|
29
|
+ comparer={Comparer.hasProperties}
|
|
30
|
+ actual={dirs}
|
|
31
|
+ />,
|
|
32
|
+ <Info key="System Folders">
|
|
33
|
+ <Text>{`${JSON.stringify(dirs)}`}</Text>
|
|
34
|
+ </Info>
|
|
35
|
+ )
|
|
36
|
+ done()
|
42
|
37
|
})
|
43
|
38
|
|
44
|
39
|
describe('ls API test', (report, done) => {
|
|
@@ -286,13 +281,10 @@ describe('cp API test', {timeout : 10000},(report, done) => {
|
286
|
281
|
})
|
287
|
282
|
|
288
|
283
|
describe('ASCII data test', (report, done) => {
|
289
|
|
- let p = null
|
|
284
|
+ let p = dirs.DocumentDir + '/ASCII-test-' + Date.now()
|
290
|
285
|
let expect = 'fetch-blob-'+Date.now()
|
291
|
|
- fs.getSystemDirs()
|
292
|
|
- .then((dirs) => {
|
293
|
|
- p = dirs.DocumentDir + '/ASCII-test-' + Date.now()
|
294
|
|
- return fs.createFile(p, 'utf8')
|
295
|
|
- })
|
|
286
|
+
|
|
287
|
+ fs.createFile(p, 'utf8')
|
296
|
288
|
.then(() => {
|
297
|
289
|
return fs.writeStream(p, 'ascii', false)
|
298
|
290
|
})
|
|
@@ -326,66 +318,56 @@ describe('ASCII data test', (report, done) => {
|
326
|
318
|
})
|
327
|
319
|
|
328
|
320
|
describe('ASCII file test', (report, done) => {
|
329
|
|
- let p = ''
|
|
321
|
+ let p = dirs.DocumentDir + '/'
|
330
|
322
|
let filename = ''
|
331
|
323
|
let expect = []
|
332
|
324
|
let base64 = RNFetchBlob.base64
|
333
|
|
- fs.getSystemDirs().then((dirs) => {
|
334
|
|
- p = dirs.DocumentDir + '/'
|
335
|
|
- filename = 'ASCII-file-test' + Date.now() + '.txt'
|
336
|
|
- expect = 'ascii test ' + Date.now()
|
337
|
|
- return fs.createFile(p + filename, getASCIIArray(expect), 'ascii')
|
338
|
|
- })
|
339
|
|
- .then(() => {
|
340
|
|
- fs.readStream(p + filename, 'base64').then((rs) => {
|
341
|
|
- let actual = ''
|
342
|
|
- rs.open()
|
343
|
|
- rs.onData((chunk) => {
|
344
|
|
- actual += chunk
|
345
|
|
- })
|
346
|
|
- rs.onEnd(() => {
|
347
|
|
- report(<Assert key="written data verify"
|
348
|
|
- expect={expect}
|
349
|
|
- actual={base64.decode(actual)}/>)
|
350
|
|
- done()
|
|
325
|
+ filename = 'ASCII-file-test' + Date.now() + '.txt'
|
|
326
|
+ expect = 'ascii test ' + Date.now()
|
|
327
|
+ fs.createFile(p + filename, getASCIIArray(expect), 'ascii')
|
|
328
|
+ .then(() => {
|
|
329
|
+ fs.readStream(p + filename, 'base64').then((rs) => {
|
|
330
|
+ let actual = ''
|
|
331
|
+ rs.open()
|
|
332
|
+ rs.onData((chunk) => {
|
|
333
|
+ actual += chunk
|
|
334
|
+ })
|
|
335
|
+ rs.onEnd(() => {
|
|
336
|
+ report(<Assert key="written data verify"
|
|
337
|
+ expect={expect}
|
|
338
|
+ actual={base64.decode(actual)}/>)
|
|
339
|
+ done()
|
|
340
|
+ })
|
351
|
341
|
})
|
352
|
342
|
})
|
353
|
|
- })
|
354
|
343
|
})
|
355
|
344
|
|
356
|
345
|
describe('format conversion', (report, done) => {
|
357
|
|
- let p = ''
|
358
|
|
- fs.getSystemDirs().then((dirs) => {
|
359
|
|
- p = dirs.DocumentDir + '/foo-' + Date.now()
|
360
|
|
- return fs.createFile(p, [102, 111, 111], 'ascii')
|
361
|
|
- })
|
362
|
|
- .then(() => {
|
363
|
|
- fs.readStream(p, 'utf8').then((stream) => {
|
364
|
|
- let res = []
|
365
|
|
- stream.open()
|
366
|
|
- stream.onData((chunk) => {
|
367
|
|
- res+=chunk
|
368
|
|
- })
|
369
|
|
- stream.onEnd(() => {
|
370
|
|
- report(
|
371
|
|
- <Assert key="write utf8 and read by ascii"
|
372
|
|
- expect="foo"
|
373
|
|
- actual={res}/>)
|
374
|
|
- done()
|
|
346
|
+ let p = dirs.DocumentDir + '/foo-' + Date.now()
|
|
347
|
+ fs.createFile(p, [102, 111, 111], 'ascii')
|
|
348
|
+ .then(() => {
|
|
349
|
+ fs.readStream(p, 'utf8').then((stream) => {
|
|
350
|
+ let res = []
|
|
351
|
+ stream.open()
|
|
352
|
+ stream.onData((chunk) => {
|
|
353
|
+ res+=chunk
|
|
354
|
+ })
|
|
355
|
+ stream.onEnd(() => {
|
|
356
|
+ report(
|
|
357
|
+ <Assert key="write utf8 and read by ascii"
|
|
358
|
+ expect="foo"
|
|
359
|
+ actual={res}/>)
|
|
360
|
+ done()
|
|
361
|
+ })
|
375
|
362
|
})
|
376
|
363
|
})
|
377
|
|
- })
|
378
|
364
|
})
|
379
|
365
|
|
380
|
366
|
describe('stat and lstat test', (report, done) => {
|
381
|
|
- let p = ''
|
382
|
|
- let dirs = null
|
|
367
|
+ let p = dirs.DocumentDir + '/' + 'ls-stat-test' + Date.now()
|
383
|
368
|
let file = null
|
384
|
|
- fs.getSystemDirs().then((resp) => {
|
385
|
|
- dirs = resp
|
386
|
|
- p = dirs.DocumentDir + '/' + 'ls-stat-test' + Date.now()
|
387
|
|
- return fs.lstat(dirs.DocumentDir)
|
388
|
|
- })
|
|
369
|
+
|
|
370
|
+ fs.lstat(dirs.DocumentDir)
|
389
|
371
|
// stat a folder
|
390
|
372
|
.then((stat) => {
|
391
|
373
|
report(
|