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

Commit 2fb18c8

Browse files
committed
Add #140 test case and test server API
1 parent adb8878 commit 2fb18c8

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

test-server/server.js

+16
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ app.all('/timeout408/:time', (req, res) => {
166166
}, 5000)
167167
})
168168

169+
app.get('/10s-download', (req,res) => {
170+
var count = 0
171+
var data = ''
172+
for(var i =0;i<1024000;i++)
173+
data += '1'
174+
res.set('Contet-Length', 1024000*10)
175+
var it = setInterval(() => {
176+
res.write(data)
177+
count++
178+
if(count == 10) {
179+
clearInterval(it)
180+
res.end()
181+
}
182+
}, 1000)
183+
})
184+
169185
app.all('/long', (req, res) => {
170186
var count = 0;
171187
var it = setInterval(() => {

test/test-0.9.6.js

+50
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,55 @@ describe('support #141 breakpoint download', (report, done) => {
7979
})
8080

8181
describe('support download/upload progress interval and division #140 ', (report, done) => {
82+
let tick = 0
83+
let records = []
84+
let last = Date.now()
85+
RNFetchBlob.config({
86+
timeout : 30000
87+
}).fetch('GET', `${TEST_SERVER_URL}/10s-download`, {
88+
'Cache-Control' : 'no-store'
89+
})
90+
.progress({interval : 1000},(current, total) => {
91+
records.push(Date.now() - last)
92+
last = Date.now()
93+
console.log(current, '/', total, current/total)
94+
tick ++
95+
})
96+
.then(() => {
97+
let avg = 0
98+
for(let i in records) {
99+
avg+=records[i]
100+
}
101+
avg/=records.length
102+
report(<Assert key="interval > 900" expect={900} comparer={Comparer.smaller} actual={avg}/>)
103+
report(<Assert key="interval < 1200" expect={1200} comparer={Comparer.greater} actual={avg}/>)
104+
upload()
105+
})
106+
107+
function upload() {
108+
let count = 0
109+
let image = RNTest.prop('image')
110+
RNFetchBlob.config({
111+
fileCache : true
112+
})
113+
.fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
114+
.then((res) => {
115+
return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
116+
Authorization : `Bearer ${DROPBOX_TOKEN}`,
117+
'Dropbox-API-Arg': '{\"path\": \"/rn-upload/intervalTest.png\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
118+
'Content-Type' : 'application/octet-stream',
119+
}, RNFetchBlob.wrap(res.path()))
120+
.uploadProgress({count : 10, interval : -1}, (current, total) => {
121+
count++
122+
console.log(current, total)
123+
})
124+
})
125+
.then(() => {
126+
report(<Assert key="count is correct" expect={10} actual={count}/>)
127+
done()
128+
})
129+
130+
}
131+
82132

83133
})

0 commit comments

Comments
 (0)