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

Commit ddfded1

Browse files
committed
Add test server API
1 parent f47b910 commit ddfded1

File tree

2 files changed

+74
-44
lines changed

2 files changed

+74
-44
lines changed

test-server/server.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ app.use(function(req, res, next) {
6565
next();
6666
})
6767

68+
app.all('/upload', (req, res) => {
69+
console.log(req.headers)
70+
res.send(req.headers)
71+
})
72+
6873
app.get('/unicode', (req, res) => {
6974
res.send({ data:'你好!'})
7075
})

test/test-0.9.4.js

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,54 +27,79 @@ const dirs = RNFetchBlob.fs.dirs
2727

2828
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
2929

30-
describe('issue #105', (report, done) => {
31-
let tmp = null
32-
RNFetchBlob
33-
.config({ fileCache : true })
34-
.fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
35-
.then((res) => {
36-
tmp = res.path()
37-
return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
38-
'Content-Type' : 'multipart/form-data',
39-
'Expect' : '100-continue'
40-
}, [
41-
{ name : 'data', data : 'issue#105 test' },
42-
{ name : 'file', filename : 'github.png', data : RNFetchBlob.wrap(tmp) }
43-
])
44-
})
45-
.then((res) => {
46-
done()
47-
})
48-
})
30+
// describe('issue #105', (report, done) => {
31+
// let tmp = null
32+
// RNFetchBlob
33+
// .config({ fileCache : true })
34+
// .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
35+
// .then((res) => {
36+
// tmp = res.path()
37+
// return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
38+
// 'Content-Type' : 'multipart/form-data',
39+
// 'Expect' : '100-continue'
40+
// }, [
41+
// { name : 'data', data : 'issue#105 test' },
42+
// { name : 'file', filename : 'github.png', data : RNFetchBlob.wrap(tmp) }
43+
// ])
44+
// })
45+
// .then((res) => {
46+
// done()
47+
// })
48+
// })
49+
//
50+
// describe('issue #106', (report, done) => {
51+
//
52+
// fetch('https://rnfb-test-app.firebaseapp.com/6m-json.json')
53+
// .then((res) => {
54+
// console.log('## converted')
55+
// return res.json()
56+
// })
57+
// .then((data) => {
58+
// // console.log(data)
59+
// report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
60+
// done()
61+
// })
62+
//
63+
// })
64+
//
65+
// describe('issue #111 get redirect destination', (report, done) => {
66+
// RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67+
// .then((res) => {
68+
// report(
69+
// <Assert key="redirect history should tracable"
70+
// expect={2}
71+
// actual={res.info().redirects.length}/>,
72+
// <Assert key="redirect history verify"
73+
// expect={[`${TEST_SERVER_URL}/redirect`, `${TEST_SERVER_URL}/public/github.png`]}
74+
// comparer={Comparer.equalToArray}
75+
// actual={res.info().redirects}/>,
76+
// )
77+
// done()
78+
// })
79+
// })
4980

50-
describe('issue #106', (report, done) => {
81+
describe('chunked encoding option test', (report, done) => {
5182

52-
fetch('https://rnfb-test-app.firebaseapp.com/6m-json.json')
83+
let path = null
84+
let base64 = null
85+
86+
RNFetchBlob
87+
// .config({ fileCache : true })
88+
.fetch('GET', `${TEST_SERVER_URL}/public/1600k-img-dummy.jpg`)
5389
.then((res) => {
54-
console.log('## converted')
55-
return res.json()
90+
base64 = res.base64()
91+
return RNFetchBlob
92+
.fetch('POST', `${TEST_SERVER_URL}/upload`, {
93+
'Content-Type' : 'application/octet-stream;BASE64'
94+
}, base64)
5695
})
57-
.then((data) => {
58-
// console.log(data)
59-
report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
96+
.then((res) => {
97+
let headers = res.info().headers
98+
console.log(res.text())
99+
report(<Assert key="request should not use chunked encoding"
100+
expect={undefined}
101+
actual={headers['transfer-encoding']}/>)
102+
fs.unlink(path)
60103
done()
61104
})
62-
63-
})
64-
65-
describe('issue #111 get redirect destination', (report, done) => {
66-
RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67-
.then((res) => {
68-
report(
69-
<Assert key="redirect history should tracable"
70-
expect={2}
71-
actual={res.info().redirects.length}/>,
72-
<Assert key="redirect history verify"
73-
expect={[`${TEST_SERVER_URL}/redirect`, `${TEST_SERVER_URL}/public/github.png`]}
74-
comparer={Comparer.equalToArray}
75-
actual={res.info().redirects}/>,
76-
)
77-
done()
78-
})
79-
80105
})

0 commit comments

Comments
 (0)