Ben Hsieh 8 лет назад
Родитель
Сommit
c37ba9ac99
2 измененных файлов: 65 добавлений и 1 удалений
  1. 14
    1
      test-server/server.js
  2. 51
    0
      test/test-background.js

+ 14
- 1
test-server/server.js Просмотреть файл

@@ -166,7 +166,20 @@ app.all('/timeout408/:time', (req, res) => {
166 166
   }, 5000)
167 167
 })
168 168
 
169
-app.all('/long', (req, res) => {
169
+app.all('/long/:ticks', (req, res) => {
170
+  var count = 0;
171
+  var it = setInterval(() => {
172
+    console.log('write data', count)
173
+    res.write('a')
174
+    if(++count > req.params.ticks){
175
+      clearInterval(it)
176
+      res.end()
177
+    }
178
+  }, 1000);
179
+
180
+})
181
+
182
+app.all('/long/', (req, res) => {
170 183
   var count = 0;
171 184
   var it = setInterval(() => {
172 185
     console.log('write data', count)

+ 51
- 0
test/test-background.js Просмотреть файл

@@ -0,0 +1,51 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import RNFetchBlob from 'react-native-fetch-blob'
4
+import {
5
+  StyleSheet,
6
+  Text,
7
+  View,
8
+  ScrollView,
9
+  Linking,
10
+  Platform,
11
+  Dimensions,
12
+  AsyncStorage,
13
+  Image,
14
+} from 'react-native';
15
+const JSONStream = RNFetchBlob.JSONStream
16
+const fs = RNFetchBlob.fs
17
+const { Assert, Comparer, Info, prop } = RNTest
18
+const describe = RNTest.config({
19
+  group : 'background',
20
+  run : true,
21
+  expand : true,
22
+  timeout : 20000,
23
+})
24
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
25
+const dirs = RNFetchBlob.fs.dirs
26
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
27
+let begin = Date.now()
28
+
29
+describe('background http response', (report, done) => {
30
+  let count = 0
31
+
32
+  let task = RNFetchBlob.config({
33
+    timeout : -1
34
+  }).fetch('GET', `${TEST_SERVER_URL}/long/3600`, {
35
+    'Cache-Control' : 'no-store'
36
+  })
37
+
38
+  task.expire(() => {
39
+    done()
40
+  })
41
+
42
+  task.catch((err) => {
43
+    console.log(err)
44
+  })
45
+
46
+  task.then((res) => {
47
+    console.log('resp response received', res.data.length)
48
+    // done()
49
+  })
50
+
51
+})