Преглед на файлове

Add #140 test case and test server API

Ben Hsieh преди 8 години
родител
ревизия
2fb18c8130
променени са 2 файла, в които са добавени 66 реда и са изтрити 0 реда
  1. 16
    0
      test-server/server.js
  2. 50
    0
      test/test-0.9.6.js

+ 16
- 0
test-server/server.js Целия файл

@@ -166,6 +166,22 @@ app.all('/timeout408/:time', (req, res) => {
166 166
   }, 5000)
167 167
 })
168 168
 
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
+
169 185
 app.all('/long', (req, res) => {
170 186
   var count = 0;
171 187
   var it = setInterval(() => {

+ 50
- 0
test/test-0.9.6.js Целия файл

@@ -79,5 +79,55 @@ describe('support #141 breakpoint download', (report, done) => {
79 79
 })
80 80
 
81 81
 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
+
82 132
 
83 133
 })