Browse Source

Add test case and test API for #264

Ben Hsieh 8 years ago
parent
commit
e7a0f892f5
2 changed files with 43 additions and 0 deletions
  1. 7
    0
      test-server/server.js
  2. 36
    0
      test/test-0.10.3.js

+ 7
- 0
test-server/server.js View File

240
   res.end()
240
   res.end()
241
 })
241
 })
242
 
242
 
243
+app.all('/interrupt', (req, res) => {
244
+  res.set('Content-Length', 10240000)
245
+  setInterval(() => {
246
+    res.write('A')
247
+  }, 300)
248
+})
249
+
243
 app.all('/cookie-echo', (req, res) => {
250
 app.all('/cookie-echo', (req, res) => {
244
   res.send(req.headers.cookie)
251
   res.send(req.headers.cookie)
245
 })
252
 })

+ 36
- 0
test/test-0.10.3.js View File

113
   })
113
   })
114
 
114
 
115
 })
115
 })
116
+
117
+describe('#264 network exceptions should be catachable', (report, done) => {
118
+
119
+  let task = RNFetchBlob
120
+  .config({ fileCache : true})
121
+  .fetch('GET',`${TEST_SERVER_URL}/interrupt`)
122
+  task
123
+  .then((res) => {
124
+    console.log(res.data)
125
+    console.log(res.info())
126
+  })
127
+  .catch((err) => {
128
+    console.log('##err',err)
129
+  })
130
+
131
+})
132
+
133
+describe('readstream with empty buffer', (report, done) => {
134
+
135
+  let data = { cool : 100 }
136
+  let path = dirs.DocumentDir + '/test' + Date.now()
137
+  let result = ''
138
+
139
+  fs.writeFile(path, JSON.stringify(data), 'utf8')
140
+    .then(() => fs.readStream(path, 'utf8'))
141
+    .then((stream) => {
142
+      stream.open()
143
+      stream.onData((chunk) => { result += chunk })
144
+      stream.onError((err) => console.log('err' + err))
145
+      stream.onEnd(() => {
146
+        console.log(result)
147
+        console.log(JSON.parse(result))
148
+      })
149
+    })
150
+
151
+})