Browse Source

Add test case #118

Ben Hsieh 8 years ago
parent
commit
4a6ca380cd
1 changed files with 21 additions and 6 deletions
  1. 21
    6
      test/test-0.9.4.js

+ 21
- 6
test/test-0.9.4.js View File

@@ -9,6 +9,7 @@ import {
9 9
   Platform,
10 10
   Dimensions,
11 11
   Image,
12
+  TouchableOpacity,
12 13
 } from 'react-native';
13 14
 
14 15
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
@@ -65,6 +66,7 @@ describe('issue #106', (report, done) => {
65 66
 describe('issue #111 get redirect destination', (report, done) => {
66 67
   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67 68
   .then((res) => {
69
+    console.log(res.info())
68 70
     report(
69 71
       <Assert key="redirect history should tracable"
70 72
         expect={2}
@@ -107,17 +109,26 @@ describe('chunked encoding option test', (report, done) => {
107 109
 describe('#118 readStream performance prepare the file', (report, done) => {
108 110
   let cache = null
109 111
   let size = 0
112
+  let size2 = 0
110 113
   let tick = Date.now()
114
+  let tick2 = Date.now()
111 115
   let start = -1
116
+  let start2 = -1
112 117
   let count = 0
113 118
 
114
-  RNFetchBlob.config({fileCache : true})
119
+  let task = RNFetchBlob.config({fileCache : true})
115 120
     .fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
116
-    .then((res) => {
121
+  task.progress((current, total) => {
122
+    report(<Info key="prepare file" uid="prepare">
123
+      <Text key="pg"> {Math.floor(current/total*100)}% </Text>
124
+    </Info>)
125
+  })
126
+  task.then((res) => {
117 127
       report(<Info key="preparation complete"><Text>start in 3 seconds</Text></Info>)
118 128
       cache = res.path()
119
-      setTimeout(() => {
120
-        fs.readStream(cache, 'utf8', 1024000)
129
+      setTimeout(readFile, 2500)
130
+      function readFile() {
131
+        fs.readStream(cache, 'utf8', 102400, 10)
121 132
           .then((stream) => {
122 133
             stream.open()
123 134
             start = Date.now()
@@ -125,9 +136,13 @@ describe('#118 readStream performance prepare the file', (report, done) => {
125 136
               count++
126 137
               size += chunk.length
127 138
               if(Date.now() - tick > 500) {
139
+                console.log(size, ' read')
128 140
                 tick = Date.now()
129 141
                 report(
130
-                  <Info key="size" uid="100"><Text>{size} bytes read</Text></Info>)
142
+                  <Info key="size" uid="100">
143
+                    <Text key="AA">File 1 {size}/22000000 bytes read</Text>
144
+                    <Text key="BB">File 2 {size2}/22000000 bytes read</Text>
145
+                  </Info>)
131 146
               }
132 147
             })
133 148
             stream.onEnd(() => {
@@ -144,7 +159,7 @@ describe('#118 readStream performance prepare the file', (report, done) => {
144 159
               })
145 160
             })
146 161
           })
147
-      }, 3000)
162
+      }
148 163
     })
149 164
 })
150 165