@@ -45,60 +45,34 @@ describe('Upload and download large file', (report, done) => {
4545 deb = Date . now ( )
4646 report ( < Info uid = "200" key = "progress" >
4747 < Text >
48- { `download ${ now } / ${ total } bytes (${ Math . floor ( now / ( Date . now ( ) - begin ) ) } kb/s)` }
48+ { `download ${ now } / ${ total } bytes (${ Math . floor ( now / ( Date . now ( ) - begin ) ) } kb/s) ${ ( 100 * now / total ) . toFixed ( 2 ) } % ` }
4949 </ Text >
5050 </ Info > )
5151 } )
5252 . then ( ( res ) => {
5353 bigfile = res . path ( )
54+ return fs . stat ( bigfile )
55+ } )
56+ . then ( ( stat ) => {
57+ report ( < Info key = "big file stat" >
58+ < Text > { JSON . stringify ( stat ) } </ Text >
59+ </ Info > )
5460 done ( )
5561 } )
56- // .then((res) => {
57- // bigfile = res.path()
58- // try {
59- // deb = Date.now()
60- // let promise = RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
61- // Authorization : `Bearer ${DROPBOX_TOKEN}`,
62- // 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
63- // 'Content-Type' : 'application/octet-stream',
64- // }, RNFetchBlob.wrap(res.path()))
65- // promise.uploadProgress((now, total) => {
66- // if(Date.now() - deb < 1000)
67- // return
68- // deb = Date.now()
69- // if(begin2 === -1)
70- // begin2 = Date.now()
71- // let speed = Math.floor(now / (Date.now() - begin2))
72- // report(<Info uid="100" key="progress">
73- // <Text>
74- // {`upload ${now} / ${total} bytes (${speed} kb/s)` }
75- // {` ${Math.floor((total-now)/speed/1000)} seconds left` }
76- // </Text>
77- // </Info>)
78- // })
79- // return promise
80- // } catch(err) { console.log(err) }
81- // })
82- // .then((res) => {
83- // report(<Assert
84- // key="upload should success without crashing app"
85- // expect={filename}
86- // actual={res.json().name}/>)
87- // done()
88- // })
8962} )
9063
9164describe ( 'cancel task should work properly' , ( report , done ) => {
9265 let filename = Platform . OS + '-0.7.0-cancel-test-22mb-dummy-' + Date . now ( )
9366 let bytesWitten = 0
9467 let deb = Date . now ( )
9568 let begin = - 1
96- let promise = RNFetchBlob . fetch ( 'POST' , 'https://content.dropboxapi.com/2/files/upload' , {
69+ let task = RNFetchBlob . fetch ( 'POST' , 'https://content.dropboxapi.com/2/files/upload' , {
9770 Authorization : `Bearer ${ DROPBOX_TOKEN } ` ,
9871 'Dropbox-API-Arg' : '{\"path\": \"/rn-upload/' + filename + '\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}' ,
9972 'Content-Type' : 'application/octet-stream' ,
10073 } , RNFetchBlob . wrap ( bigfile ) )
101- promise . uploadProgress ( ( now , total ) => {
74+
75+ task . uploadProgress ( ( now , total ) => {
10276 bytesWitten = now
10377 if ( Date . now ( ) - deb < 1000 )
10478 return
@@ -115,7 +89,7 @@ describe('cancel task should work properly', (report, done) => {
11589 } )
11690 let checkpoint1 = 0
11791 Timer . setTimeout ( ( ) => {
118- promise . cancel ( )
92+ task . cancel ( )
11993 } , 5000 )
12094 Timer . setTimeout ( ( ) => {
12195 checkpoint1 = bytesWitten
@@ -124,17 +98,22 @@ describe('cancel task should work properly', (report, done) => {
12498 report ( < Assert key = "data should not write to stream after task is canceled"
12599 expect = { checkpoint1 }
126100 actual = { bytesWitten } /> )
127- done ( )
101+ fs . unlink ( bigfile ) . then ( ( ) => {
102+ done ( )
103+ } )
128104 } , 10000 )
129- promise . then ( ( res ) => {
130- report (
131- < Assert key = "task not canceled"
132- expected = { false }
105+
106+ task
107+ . then ( ( res ) => {
108+ report (
109+ < Assert key = "task not canceled"
110+ expected = { false }
111+ actual = { true } /> )
112+ } )
113+ . catch ( ( resp ) => {
114+ report ( < Assert key = "task cancelled rejection should be catachable"
115+ expect = { true }
133116 actual = { true } /> )
134- } )
135- promise . catch ( ( resp ) => {
136- report ( < Assert key = "task cancelled rejection should be catachable"
137- expect = { true }
138- actual = { true } /> )
139- } )
117+ } )
118+
140119} )
0 commit comments