Selaa lähdekoodia

Change XMLHttpRequest test case

Ben Hsieh 7 vuotta sitten
vanhempi
commit
fb2576838c
4 muutettua tiedostoa jossa 43 lisäystä ja 21 poistoa
  1. 4
    1
      test-server/server.js
  2. 21
    5
      test/test-0.8.2.js
  3. 3
    3
      test/test-init.js
  4. 15
    12
      test/test-xmlhttp.js

+ 4
- 1
test-server/server.js Näytä tiedosto

@@ -138,6 +138,7 @@ app.all('/xhr-code/:code', (req, res) => {
138 138
 
139 139
 app.all('/xhr-header', (req, res) => {
140 140
   console.log(req.headers)
141
+  res.header('Content-Type', 'application/json')
141 142
   res.send(req.headers)
142 143
 })
143 144
 
@@ -147,11 +148,13 @@ app.post('/upload', bodyParser.urlencoded({ extended : true }), (req, res) => {
147 148
   res.status(200).send(req.body)
148 149
 })
149 150
 
150
-app.all('/timeout', (req, res) => {
151
+app.all('/timeout408', (req, res) => {
151 152
   setTimeout(function() {
152 153
     res.status(408).send('request timed out.')
153 154
   }, 5000)
155
+})
154 156
 
157
+app.all('/timeout', (req, res) => {
155 158
 })
156 159
 
157 160
 function formUpload(req, res) {

+ 21
- 5
test/test-0.8.2.js Näytä tiedosto

@@ -32,8 +32,8 @@ const dirs = RNFetchBlob.fs.dirs
32 32
 
33 33
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
34 34
 
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
+
37 37
   fetch(`${TEST_SERVER_URL}/unicode`, {
38 38
     method : 'GET'
39 39
   })
@@ -47,17 +47,33 @@ describe('whatwg-fetch - GET should work correctly', (report, done) => {
47 47
   })
48 48
 })
49 49
 
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
+
50 66
 RNTest.config({
51 67
   group : '0.8.2',
52 68
   run : true,
53
-  expand : false,
69
+  expand : true,
54 70
   timeout : 24000
55 71
 })('request should not retry after timed out', (report, done) => {
56 72
 
57 73
   let count = 0
58 74
   RNFetchBlob
59
-    .config({ timeout : 3000 })
60
-    .fetch('GET', `${TEST_SERVER_URL}/timeout`)
75
+    // .config({timeout : 2000})
76
+    .fetch('GET', `${TEST_SERVER_URL}/timeout408`)
61 77
     .then((res) => {
62 78
       report(<Assert key="request should not success" expect={true} actual={false}/>)
63 79
     })

+ 3
- 3
test/test-init.js Näytä tiedosto

@@ -66,10 +66,10 @@ describe('GET image from server', (report, done) => {
66 66
 // require('./test-0.6.3')
67 67
 // require('./test-0.7.0')
68 68
 // require('./test-0.8.0')
69
-require('./test-0.8.2')
69
+// require('./test-0.8.2')
70 70
 // require('./test-fs')
71
-// require('./test-xmlhttp')
71
+require('./test-xmlhttp')
72 72
 // require('./test-blob')
73
-// require('./test-firebase')
73
+require('./test-firebase')
74 74
 // require('./test-android')
75 75
 // require('./benchmark')

+ 15
- 12
test/test-xmlhttp.js Näytä tiedosto

@@ -120,21 +120,23 @@ describe('HTTP error should not throw error event', (report, done) => {
120 120
     xhr.open(method, `${TEST_SERVER_URL}/xhr-code/${code}`)
121 121
     xhr.onreadystatechange = function() {
122 122
       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
+      }
133 135
     }
134 136
     xhr.onerror = function() {
135 137
       report(
136 138
         <Assert
137
-          key={'HTTP error should not throw error event'}
139
+          key={`HTTP error ${code} should not throw error event`}
138 140
           expect={false}
139 141
           actual={true}/>)
140 142
     }
@@ -237,6 +239,7 @@ describe('upload progress event test', (report, done) => {
237 239
   }
238 240
   xhr.onreadystatechange = function() {
239 241
     if(this.readyState == XMLHttpRequest.DONE) {
242
+      console.log(xhr)
240 243
       report(
241 244
         <Assert key="reponse should correct"
242 245
           expect={time}
@@ -304,6 +307,6 @@ describe('upload progress event should not be triggered when body is empty', (re
304 307
       done()
305 308
     }
306 309
   }
307
-  xhr.open('GET', `${TEST_SERVER_URL}/pulbic/github.png`)
310
+  xhr.open('GET', `${TEST_SERVER_URL}/public/github.png`)
308 311
   xhr.send()
309 312
 })