Skip to content

Commit e7a0f89

Browse files
committed
Add test case and test API for #264
1 parent 288f10d commit e7a0f89

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test-server/server.js

+7
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ app.all('/cookie/:data', (req, res) => {
240240
res.end()
241241
})
242242

243+
app.all('/interrupt', (req, res) => {
244+
res.set('Content-Length', 10240000)
245+
setInterval(() => {
246+
res.write('A')
247+
}, 300)
248+
})
249+
243250
app.all('/cookie-echo', (req, res) => {
244251
res.send(req.headers.cookie)
245252
})

test/test-0.10.3.js

+36
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,39 @@ describe('#263 parallel request', (report, done) => {
113113
})
114114

115115
})
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+
})

0 commit comments

Comments
 (0)