Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit a73f437

Browse files
committed
Change test cases
1 parent 1bbe292 commit a73f437

File tree

4 files changed

+357
-249
lines changed

4 files changed

+357
-249
lines changed

test-server/server.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,25 @@ app.post('/upload', bodyParser.urlencoded({ extended : true }), (req, res) => {
148148
res.status(200).send(req.body)
149149
})
150150

151-
app.all('/timeout408', (req, res) => {
151+
app.all('/timeout408/:time', (req, res) => {
152152
setTimeout(function() {
153153
res.status(408).send('request timed out.')
154154
}, 5000)
155155
})
156156

157+
app.all('/long', (req, res) => {
158+
var count = 0;
159+
var it = setInterval(() => {
160+
console.log('write data', count)
161+
res.write('a')
162+
if(++count >60){
163+
clearInterval(it)
164+
res.end()
165+
}
166+
}, 1000);
167+
168+
})
169+
157170
app.all('/timeout', (req, res) => {
158171
})
159172

test/test-0.8.2.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe('#73 unicode response BASE64 content test', (report, done) => {
4141
return res.json()
4242
})
4343
.then((data) => {
44-
console.log(data)
4544
report(<Assert key="data should correct" expect={'你好!'} actual={data.data}/>)
4645
done()
4746
})
@@ -63,25 +62,48 @@ describe('#73 unicode response content test', (report, done) => {
6362
})
6463
})
6564

66-
RNTest.config({
65+
describe = RNTest.config({
6766
group : '0.8.2',
6867
run : true,
6968
expand : true,
7069
timeout : 24000
71-
})('request should not retry after timed out', (report, done) => {
70+
})
71+
72+
describe('request should not retry after timed out', (report, done) => {
7273

7374
let count = 0
74-
RNFetchBlob
75-
// .config({timeout : 2000})
76-
.fetch('GET', `${TEST_SERVER_URL}/timeout408`)
77-
.then((res) => {
78-
report(<Assert key="request should not success" expect={true} actual={false}/>)
79-
})
80-
.catch(() => {
81-
count ++
82-
})
75+
let task = RNFetchBlob
76+
.fetch('GET', `${TEST_SERVER_URL}/timeout408/${Date.now()}`)
77+
task.then((res) => {
78+
report(<Assert key="request should not success" expect={true} actual={false}/>)
79+
})
80+
.catch(() => {
81+
task.cancel()
82+
count ++
83+
})
8384
setTimeout(() => {
8485
report(<Assert key="request does not retry" expect={1} actual={count}/>)
8586
done()
86-
}, 8000)
87+
}, 12000)
88+
})
89+
90+
describe = RNTest.config({
91+
group : '0.8.2',
92+
run : true,
93+
expand : true,
94+
timeout : 65000
95+
})
96+
97+
describe('long live download or upload task won\'t timeout', (report, done) => {
98+
99+
RNFetchBlob.config({timeout : 0})
100+
.fetch('GET', `${TEST_SERVER_URL}/long/`)
101+
.then((res) => {
102+
report(
103+
<Assert key="download not terminated" expect={true} actual={true}/>,
104+
<Info key={res.text()}/>)
105+
done()
106+
})
107+
108+
87109
})

test/test-fetch.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import RNTest from './react-native-testkit/'
2+
import React from 'react'
3+
import RNFetchBlob from 'react-native-fetch-blob'
4+
5+
import {
6+
StyleSheet,
7+
Text,
8+
View,
9+
ScrollView,
10+
Platform,
11+
Dimensions,
12+
Image,
13+
} from 'react-native';
14+
15+
window.Blob = RNFetchBlob.polyfill.Blob
16+
window.fetch = new RNFetchBlob.polyfill.Fetch({
17+
auto : true,
18+
binaryContentTypes : ['image/', 'video/', 'audio/']
19+
}).build()
20+
21+
const fs = RNFetchBlob.fs
22+
const { Assert, Comparer, Info, prop } = RNTest
23+
const describe = RNTest.config({
24+
group : 'Fetch polyfill',
25+
run : true,
26+
expand : true,
27+
timeout : 10000,
28+
})
29+
const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
30+
const dirs = RNFetchBlob.fs.dirs
31+
32+
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
33+
34+
describe('GET request test : text -> any', (report, done) => {
35+
36+
function get(fn1, fn2) {
37+
return fetch(`${TEST_SERVER_URL}/unicode`, { method : 'GET'})
38+
.then((res) => fn1(res))
39+
.then((data) => fn2(data))
40+
}
41+
let promises =
42+
[
43+
get((res) => res.json(), (json) => {
44+
report(<Assert key="json data correct" expect={'你好!'} actual={json.data}/>)
45+
}),
46+
get((res) => res.text(), (text) => {
47+
report(<Assert key="text data correct" expect={'你好!'} actual={JSON.parse(text).data}/>)
48+
}),
49+
get((res) => res.blob(), (blob) => {
50+
let path = blob.getRNFetchBlobRef()
51+
return fs.readFile(path, 'utf8').then((text) => {
52+
console.log(text)
53+
report(<Assert key="blob data correct" expect={'你好!'} actual={JSON.parse(text).data}/>)
54+
})
55+
}),
56+
// get((res) => res.arrayBuffer(), (text) => {
57+
// report(<Assert key="text data correct" expect={'你好!'} actual={JSON.parse(text).data}/>)
58+
// })
59+
]
60+
61+
Promise.all(promises).then(() => {
62+
done()
63+
})
64+
65+
})
66+
67+
describe('GET request which has json response', (report, done) => {
68+
69+
})
70+
71+
describe('GET request which has blob response', (report, done) => {
72+
73+
})

0 commit comments

Comments
 (0)