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
   Platform,
9
   Platform,
10
   Dimensions,
10
   Dimensions,
11
   Image,
11
   Image,
12
+  TouchableOpacity,
12
 } from 'react-native';
13
 } from 'react-native';
13
 
14
 
14
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
15
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
65
 describe('issue #111 get redirect destination', (report, done) => {
66
 describe('issue #111 get redirect destination', (report, done) => {
66
   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67
   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67
   .then((res) => {
68
   .then((res) => {
69
+    console.log(res.info())
68
     report(
70
     report(
69
       <Assert key="redirect history should tracable"
71
       <Assert key="redirect history should tracable"
70
         expect={2}
72
         expect={2}
107
 describe('#118 readStream performance prepare the file', (report, done) => {
109
 describe('#118 readStream performance prepare the file', (report, done) => {
108
   let cache = null
110
   let cache = null
109
   let size = 0
111
   let size = 0
112
+  let size2 = 0
110
   let tick = Date.now()
113
   let tick = Date.now()
114
+  let tick2 = Date.now()
111
   let start = -1
115
   let start = -1
116
+  let start2 = -1
112
   let count = 0
117
   let count = 0
113
 
118
 
114
-  RNFetchBlob.config({fileCache : true})
119
+  let task = RNFetchBlob.config({fileCache : true})
115
     .fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
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
       report(<Info key="preparation complete"><Text>start in 3 seconds</Text></Info>)
127
       report(<Info key="preparation complete"><Text>start in 3 seconds</Text></Info>)
118
       cache = res.path()
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
           .then((stream) => {
132
           .then((stream) => {
122
             stream.open()
133
             stream.open()
123
             start = Date.now()
134
             start = Date.now()
125
               count++
136
               count++
126
               size += chunk.length
137
               size += chunk.length
127
               if(Date.now() - tick > 500) {
138
               if(Date.now() - tick > 500) {
139
+                console.log(size, ' read')
128
                 tick = Date.now()
140
                 tick = Date.now()
129
                 report(
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
             stream.onEnd(() => {
148
             stream.onEnd(() => {
144
               })
159
               })
145
             })
160
             })
146
           })
161
           })
147
-      }, 3000)
162
+      }
148
     })
163
     })
149
 })
164
 })
150
 
165