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

Commit fb25768

Browse files
committed
Change XMLHttpRequest test case
1 parent b2f47bb commit fb25768

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

test-server/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ app.all('/xhr-code/:code', (req, res) => {
138138

139139
app.all('/xhr-header', (req, res) => {
140140
console.log(req.headers)
141+
res.header('Content-Type', 'application/json')
141142
res.send(req.headers)
142143
})
143144

@@ -147,11 +148,13 @@ app.post('/upload', bodyParser.urlencoded({ extended : true }), (req, res) => {
147148
res.status(200).send(req.body)
148149
})
149150

150-
app.all('/timeout', (req, res) => {
151+
app.all('/timeout408', (req, res) => {
151152
setTimeout(function() {
152153
res.status(408).send('request timed out.')
153154
}, 5000)
155+
})
154156

157+
app.all('/timeout', (req, res) => {
155158
})
156159

157160
function formUpload(req, res) {

test/test-0.8.2.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const dirs = RNFetchBlob.fs.dirs
3232

3333
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
3434

35-
describe('whatwg-fetch - GET should work correctly', (report, done) => {
36-
console.log(fetch)
35+
describe('#73 unicode response BASE64 content test', (report, done) => {
36+
3737
fetch(`${TEST_SERVER_URL}/unicode`, {
3838
method : 'GET'
3939
})
@@ -47,17 +47,33 @@ describe('whatwg-fetch - GET should work correctly', (report, done) => {
4747
})
4848
})
4949

50+
describe('#73 unicode response content test', (report, done) => {
51+
let expect = '中文!檔案\\u00測試 ABCDE 測試'
52+
RNFetchBlob.config({ fileCache : true })
53+
.fetch('GET', `${TEST_SERVER_URL}/public/utf8-dummy`, {
54+
method : 'GET'
55+
})
56+
.then((res) => res.readFile('utf8'))
57+
.then((data) => {
58+
report(
59+
<Assert key="data should correct"
60+
expect={expect}
61+
actual={data}/>)
62+
done()
63+
})
64+
})
65+
5066
RNTest.config({
5167
group : '0.8.2',
5268
run : true,
53-
expand : false,
69+
expand : true,
5470
timeout : 24000
5571
})('request should not retry after timed out', (report, done) => {
5672

5773
let count = 0
5874
RNFetchBlob
59-
.config({ timeout : 3000 })
60-
.fetch('GET', `${TEST_SERVER_URL}/timeout`)
75+
// .config({timeout : 2000})
76+
.fetch('GET', `${TEST_SERVER_URL}/timeout408`)
6177
.then((res) => {
6278
report(<Assert key="request should not success" expect={true} actual={false}/>)
6379
})

test/test-init.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ describe('GET image from server', (report, done) => {
6666
// require('./test-0.6.3')
6767
// require('./test-0.7.0')
6868
// require('./test-0.8.0')
69-
require('./test-0.8.2')
69+
// require('./test-0.8.2')
7070
// require('./test-fs')
71-
// require('./test-xmlhttp')
71+
require('./test-xmlhttp')
7272
// require('./test-blob')
73-
// require('./test-firebase')
73+
require('./test-firebase')
7474
// require('./test-android')
7575
// require('./benchmark')

test/test-xmlhttp.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,23 @@ describe('HTTP error should not throw error event', (report, done) => {
120120
xhr.open(method, `${TEST_SERVER_URL}/xhr-code/${code}`)
121121
xhr.onreadystatechange = function() {
122122
count++
123-
report(
124-
<Assert
125-
key={`#${count} response data of ${method} ${code} should be empty`}
126-
expect=""
127-
actual={xhr.response}/>,
128-
<Assert
129-
key={`#${count} status of ${method} ${code} should be ${code}`}
130-
expect={code}
131-
actual={xhr.status}/>
132-
)
123+
if(this.readyState == XMLHttpRequest.DONE) {
124+
report(
125+
<Assert
126+
key={`#${count} response data of ${method} ${code} should be empty`}
127+
expect=""
128+
actual={xhr.response}/>,
129+
<Assert
130+
key={`#${count} status of ${method} ${code} should be ${code}`}
131+
expect={code}
132+
actual={xhr.status}/>
133+
)
134+
}
133135
}
134136
xhr.onerror = function() {
135137
report(
136138
<Assert
137-
key={'HTTP error should not throw error event'}
139+
key={`HTTP error ${code} should not throw error event`}
138140
expect={false}
139141
actual={true}/>)
140142
}
@@ -237,6 +239,7 @@ describe('upload progress event test', (report, done) => {
237239
}
238240
xhr.onreadystatechange = function() {
239241
if(this.readyState == XMLHttpRequest.DONE) {
242+
console.log(xhr)
240243
report(
241244
<Assert key="reponse should correct"
242245
expect={time}
@@ -304,6 +307,6 @@ describe('upload progress event should not be triggered when body is empty', (re
304307
done()
305308
}
306309
}
307-
xhr.open('GET', `${TEST_SERVER_URL}/pulbic/github.png`)
310+
xhr.open('GET', `${TEST_SERVER_URL}/public/github.png`)
308311
xhr.send()
309312
})

0 commit comments

Comments
 (0)