|
@@ -45,47 +45,20 @@ describe('Upload and download large file', (report, done) => {
|
45
|
45
|
deb = Date.now()
|
46
|
46
|
report(<Info uid="200" key="progress">
|
47
|
47
|
<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)}%`}
|
49
|
49
|
</Text>
|
50
|
50
|
</Info>)
|
51
|
51
|
})
|
52
|
52
|
.then((res) => {
|
53
|
53
|
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>)
|
54
|
60
|
done()
|
55
|
61
|
})
|
56
|
|
-
|
57
|
|
-
|
58
|
|
-
|
59
|
|
-
|
60
|
|
-
|
61
|
|
-
|
62
|
|
-
|
63
|
|
-
|
64
|
|
-
|
65
|
|
-
|
66
|
|
-
|
67
|
|
-
|
68
|
|
-
|
69
|
|
-
|
70
|
|
-
|
71
|
|
-
|
72
|
|
-
|
73
|
|
-
|
74
|
|
-
|
75
|
|
-
|
76
|
|
-
|
77
|
|
-
|
78
|
|
-
|
79
|
|
-
|
80
|
|
-
|
81
|
|
-
|
82
|
|
-
|
83
|
|
-
|
84
|
|
-
|
85
|
|
-
|
86
|
|
-
|
87
|
|
-
|
88
|
|
-
|
89
|
62
|
})
|
90
|
63
|
|
91
|
64
|
describe('cancel task should work properly', (report, done) => {
|
|
@@ -93,12 +66,13 @@ describe('cancel task should work properly', (report, done) => {
|
93
|
66
|
let bytesWitten = 0
|
94
|
67
|
let deb = Date.now()
|
95
|
68
|
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', {
|
97
|
70
|
Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
98
|
71
|
'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
|
99
|
72
|
'Content-Type' : 'application/octet-stream',
|
100
|
73
|
}, RNFetchBlob.wrap(bigfile))
|
101
|
|
- promise.uploadProgress((now, total) => {
|
|
74
|
+
|
|
75
|
+ task.uploadProgress((now, total) => {
|
102
|
76
|
bytesWitten = now
|
103
|
77
|
if(Date.now() - deb < 1000)
|
104
|
78
|
return
|
|
@@ -115,7 +89,7 @@ describe('cancel task should work properly', (report, done) => {
|
115
|
89
|
})
|
116
|
90
|
let checkpoint1 = 0
|
117
|
91
|
Timer.setTimeout(() => {
|
118
|
|
- promise.cancel()
|
|
92
|
+ task.cancel()
|
119
|
93
|
}, 5000)
|
120
|
94
|
Timer.setTimeout(() => {
|
121
|
95
|
checkpoint1 = bytesWitten
|
|
@@ -124,17 +98,22 @@ describe('cancel task should work properly', (report, done) => {
|
124
|
98
|
report(<Assert key="data should not write to stream after task is canceled"
|
125
|
99
|
expect={checkpoint1}
|
126
|
100
|
actual={bytesWitten}/>)
|
127
|
|
- done()
|
|
101
|
+ fs.unlink(bigfile).then(() => {
|
|
102
|
+ done()
|
|
103
|
+ })
|
128
|
104
|
}, 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}
|
133
|
116
|
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
|
+
|
140
|
119
|
})
|