Bladeren bron

Modify test scripts

Ben Hsieh 8 jaren geleden
bovenliggende
commit
b7b59561b3
3 gewijzigde bestanden met toevoegingen van 28 en 17 verwijderingen
  1. 2
    6
      package.json
  2. 13
    0
      test-server/server.js
  3. 13
    11
      test/tests.js

+ 2
- 6
package.json Bestand weergeven

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "fetchblob",
3
-  "version": "0.4.0",
3
+  "version": "0.4.2",
4 4
   "private": true,
5 5
   "scripts": {
6 6
     "start": "node node_modules/react-native/local-cli/cli.js start",
@@ -11,10 +11,6 @@
11 11
     "chalk": "^1.1.3",
12 12
     "chokidar": "^1.5.1",
13 13
     "express": "^4.13.4",
14
-    "multer": "^1.1.0",
15
-    "npm": "^3.9.2"
16
-  },
17
-  "dependencies": {
18
-    "react-native-fetch-blob": "file:src"
14
+    "multer": "^1.1.0"  
19 15
   }
20 16
 }

+ 13
- 0
test-server/server.js Bestand weergeven

@@ -1,3 +1,8 @@
1
+/**
2
+ * @author wkh237
3
+ * @description react-native-fetch-blob test & dev server
4
+ */
5
+
1 6
 var express = require('express');
2 7
 var bodyParser = require('body-parser');
3 8
 var chokidar = require('chokidar');
@@ -74,10 +79,12 @@ app.use(upload.any())
74 79
 
75 80
 app.use('/public', express.static('./public'))
76 81
 
82
+// for redirect test
77 83
 app.get('/redirect', function(req, res) {
78 84
   res.redirect('/public/github.png')
79 85
 })
80 86
 
87
+// handle octet-stream request
81 88
 app.post('/upload', function(req, res){
82 89
 
83 90
   console.log(req.headers)
@@ -91,6 +98,12 @@ app.post('/upload', function(req, res){
91 98
 
92 99
 })
93 100
 
101
+// return an empty response
102
+app.all('/empty', function(req, res) {
103
+  res.send('')
104
+})
105
+
106
+// handle multipart/form-data request
94 107
 app.post('/upload-form', function(req, res) {
95 108
   console.log(req.headers)
96 109
   console.log(req.body)

+ 13
- 11
test/tests.js Bestand weergeven

@@ -13,9 +13,9 @@ import {
13 13
   Image,
14 14
 } from 'react-native';
15 15
 
16
-const FILENAME = `${Platform.OS}-0.4.0-${Date.now()}.png`
16
+const FILENAME = `${Platform.OS}-0.4.2-${Date.now()}.png`
17 17
 // paste your test config here
18
-const TEST_SERVER_URL = 'http://192.168.0.14:8123'
18
+const TEST_SERVER_URL = 'http://192.168.17.193:8123'
19 19
 const DROPBOX_TOKEN = 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4'
20 20
 
21 21
 const ctx = new RNTest.TestContext()
@@ -100,18 +100,20 @@ ctx.describe('Compare uploaded multipart image', async function(report) {
100 100
 })
101 101
 
102 102
 ctx.describe('Progress report test', (report) => new Promise((resolve) => {
103
-
103
+  let received = 0
104 104
   let p1 = RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
105 105
       Authorization : 'Bearer abde123eqweje'
106 106
     })
107
-  let log = []
108
-
109
-  p1.onProgress = (written, total) => {
110
-    report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
111
-    if(written === total)
112
-      report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
113
-    resolve()
114
-  }
107
+    // .progress((written, total) => {
108
+    //   // report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
109
+    //   if(written === total)
110
+    //     report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
111
+    // })
112
+    .then((resp) => {
113
+      report(<Assert key="response data should be correct event with progress listener"
114
+        expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
115
+      resolve()
116
+    })
115 117
 
116 118
 }))
117 119