Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 38905e6

Browse files
committed
#8 Change test code
1 parent 83525f1 commit 38905e6

File tree

4 files changed

+95
-112
lines changed

4 files changed

+95
-112
lines changed

test/test-0.5.x.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ describe('File stream reader error should be able to handled', (report, done) =>
8787
})
8888

8989
let localFile = null
90-
let sysDirs = null
90+
let sysDirs = RNFetchBlob.fs.dirs
91+
let dirs = RNFetchBlob.fs.dirs
9192

9293
describe('Upload from file storage', (report, done) => {
9394
let filename = ''
9495
let filepath = ''
95-
fs.getSystemDirs().then((dirs) => {
96-
sysDirs = dirs
97-
filename = Platform.OS + '0.5.0-' + Date.now() + '-from-storage.png'
98-
filepath = dirs.DocumentDir + '/' + filename
99-
return RNFetchBlob.config({ path : filepath })
100-
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
101-
})
96+
97+
filename = Platform.OS + '0.5.0-' + Date.now() + '-from-storage.png'
98+
filepath = dirs.DocumentDir + '/' + filename
99+
RNFetchBlob
100+
.config({ path : filepath })
101+
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
102102
.then((resp) => {
103103
let path = resp.path()
104104
localFile = path

test/test-android.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const { Assert, Comparer, Info, prop } = RNTest
1717
const describe = RNTest.config({
1818
group : 'Android only functions',
1919
run : Platform.OS === 'android',
20-
expand : false,
20+
expand : true,
2121
})
2222
const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
2323

@@ -26,24 +26,24 @@ let prefix = ((Platform.OS === 'android') ? 'file://' : '')
2626
// Android only tests
2727

2828
let tmpFilePath = null
29+
const dirs = RNFetchBlob.fs.dirs
2930

3031
describe('Download with notification', (report, done) => {
3132
let filePath = null
3233
let filename = `test-${Date.now()}.png`
33-
RNFetchBlob.fs.getSystemDirs().then((dirs) => {
34-
filePath = `${dirs.DownloadDir}/${filename}`
35-
return RNFetchBlob.config({
36-
path : filePath,
37-
addAndroidDownloads : {
38-
title : 'RNFetchBlob test download success',
39-
description : `File description added by RNFetchblob`,
40-
mediaScannable : true,
41-
mime : "image/png",
42-
notification : true
43-
}
44-
})
45-
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
34+
35+
filePath = `${dirs.DownloadDir}/${filename}`
36+
RNFetchBlob.config({
37+
path : filePath,
38+
addAndroidDownloads : {
39+
title : 'RNFetchBlob test download success',
40+
description : `File description added by RNFetchblob`,
41+
mediaScannable : true,
42+
mime : "image/png",
43+
notification : true
44+
}
4645
})
46+
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
4747
.then((resp) => {
4848
tmpFilePath = resp.path()
4949
report(<Info key={`image from ${tmpFilePath}`}>
@@ -57,30 +57,30 @@ describe('Download with notification', (report, done) => {
5757
})
5858

5959
describe('MediaScanner tests ', (report, done) => {
60-
let filePath = null
6160
let filename = `scannable-test-${Date.now()}.png`
62-
let dirs = null
63-
RNFetchBlob.fs.getSystemDirs().then((resp) => {
64-
dirs = resp
65-
filePath = `${dirs.DownloadDir}/${filename}`
66-
return RNFetchBlob.config({
67-
path : filePath,
68-
})
69-
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
61+
let filePath = `${dirs.DownloadDir}/${filename}`
62+
RNFetchBlob.config({
63+
path : filePath,
7064
})
65+
.fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
7166
.then((resp) => {
7267
tmpFilePath = resp.path()
7368
return RNFetchBlob.fs.scanFile([
7469
{ path:resp.path() }
7570
])
76-
.then(() => {
77-
report(<Assert key="scan success" expect={true} actual={true}/>)
78-
return RNFetchBlob
79-
.config({
80-
path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
81-
})
82-
.fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
83-
})
71+
})
72+
.then(() => {
73+
report(<Assert key="scan success" expect={true} actual={true}/>)
74+
console.log(dirs)
75+
for(let i in dirs) {
76+
console.log(i)
77+
}
78+
console.log(dirs.DCIMDir)
79+
return RNFetchBlob
80+
.config({
81+
path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
82+
})
83+
.fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
8484
})
8585
.then((resp) => {
8686
fs.scanFile([{

test/test-fs.js

Lines changed: 52 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,21 @@ const describe = RNTest.config({
1919
})
2020

2121
let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
22-
let dirs = null
22+
let dirs = RNFetchBlob.fs.dirs
2323

2424
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()
4237
})
4338

4439
describe('ls API test', (report, done) => {
@@ -286,13 +281,10 @@ describe('cp API test', {timeout : 10000},(report, done) => {
286281
})
287282

288283
describe('ASCII data test', (report, done) => {
289-
let p = null
284+
let p = dirs.DocumentDir + '/ASCII-test-' + Date.now()
290285
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')
296288
.then(() => {
297289
return fs.writeStream(p, 'ascii', false)
298290
})
@@ -326,66 +318,56 @@ describe('ASCII data test', (report, done) => {
326318
})
327319

328320
describe('ASCII file test', (report, done) => {
329-
let p = ''
321+
let p = dirs.DocumentDir + '/'
330322
let filename = ''
331323
let expect = []
332324
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+
})
351341
})
352342
})
353-
})
354343
})
355344

356345
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+
})
375362
})
376363
})
377-
})
378364
})
379365

380366
describe('stat and lstat test', (report, done) => {
381-
let p = ''
382-
let dirs = null
367+
let p = dirs.DocumentDir + '/' + 'ls-stat-test' + Date.now()
383368
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)
389371
// stat a folder
390372
.then((stat) => {
391373
report(

test/test-init.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('GET image from server', (report, done) => {
5151
})
5252
})
5353

54-
require('./test-fs')
55-
require('./test-0.1.x-0.4.x')
56-
require('./test-0.5.x')
54+
55+
// require('./test-fs')
56+
// require('./test-0.1.x-0.4.x')
57+
// require('./test-0.5.x')
5758
require('./test-android')

0 commit comments

Comments
 (0)