Przeglądaj źródła

Add test server API

Ben Hsieh 8 lat temu
rodzic
commit
ddfded1346
2 zmienionych plików z 74 dodań i 44 usunięć
  1. 5
    0
      test-server/server.js
  2. 69
    44
      test/test-0.9.4.js

+ 5
- 0
test-server/server.js Wyświetl plik

@@ -65,6 +65,11 @@ app.use(function(req, res, next) {
65 65
   next();
66 66
 })
67 67
 
68
+app.all('/upload', (req, res) => {
69
+  console.log(req.headers)
70
+  res.send(req.headers)
71
+})
72
+
68 73
 app.get('/unicode', (req, res) => {
69 74
   res.send({ data:'你好!'})
70 75
 })

+ 69
- 44
test/test-0.9.4.js Wyświetl plik

@@ -27,54 +27,79 @@ const dirs = RNFetchBlob.fs.dirs
27 27
 
28 28
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
29 29
 
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
+// })
49 80
 
50
-describe('issue #106', (report, done) => {
81
+describe('chunked encoding option test', (report, done) => {
51 82
 
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`)
53 89
     .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)
56 95
     })
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)
60 103
       done()
61 104
     })
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
-
80 105
 })