Procházet zdrojové kódy

Add 0.7.0 test case

Ben Hsieh před 8 roky
rodič
revize
dab97c8a77
5 změnil soubory, kde provedl 95 přidání a 27 odebrání
  1. 1
    1
      test/test-0.1.x-0.4.x.js
  2. 1
    0
      test/test-0.6.2.js
  3. 2
    19
      test/test-0.6.3.js
  4. 83
    0
      test/test-0.7.0.js
  5. 8
    7
      test/test-init.js

+ 1
- 1
test/test-0.1.x-0.4.x.js Zobrazit soubor

@@ -130,7 +130,7 @@ describe('PUT request test', (report, done) => {
130 130
       { name : 'field1', data : 'hello !!'},
131 131
       { name : 'field2', data : 'hello2 !!'}
132 132
     ])
133
-    .progress((written, total) => {
133
+    .uploadProgress((written, total) => {
134 134
       actual = written
135 135
       expect = total
136 136
     })

+ 1
- 0
test/test-0.6.2.js Zobrazit soubor

@@ -32,6 +32,7 @@ describe('upload asset from camera roll', (report, done) => {
32 32
   let tick = Date.now()
33 33
   CameraRoll.getPhotos({first : 10})
34 34
     .then((resp) => {
35
+      console.log('cameraroll', JSON.stringify(resp))
35 36
       let url = resp.edges[0].node.image.uri
36 37
       photo = url
37 38
       return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {

+ 2
- 19
test/test-0.6.3.js Zobrazit soubor

@@ -28,37 +28,21 @@ const  dirs = RNFetchBlob.fs.dirs
28 28
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
29 29
 
30 30
 false && describe('massive HTTP request', (report, done) => {
31
-  return
31
+
32 32
   let promises = []
33 33
   let progress = []
34 34
   let begin = Date.now()
35
-  for(let i=0; i<1500;i++) {
35
+  for(let i=0; i<500;i++) {
36 36
     let p = RNFetchBlob
37 37
     .config({fileCache : true})
38 38
     .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
39
-    // .progress(function(current, total){
40
-    //   progress[this] = current/total
41
-    // }.bind(i))
42 39
     promises.push(p)
43 40
   }
44
-  // let it = Timer.setInterval(() => {
45
-  //   function pgs() {
46
-  //     let res = []
47
-  //     for(var i in progress) {
48
-  //       res.push(<Text key={`download#${i}`}>{`download #${i} ${Math.floor(progress[i]*100)}%`}</Text>)
49
-  //     }
50
-  //     return res
51
-  //   }
52
-  //   report(<Info key={`progress monitor`} uid="progress">
53
-  //     {pgs()}
54
-  //   </Info>)
55
-  // }, 1000)
56 41
   Promise.all(promises).then((resps) => {
57 42
     for(let i in resps) {
58 43
       fs.unlink(resps[i].path())
59 44
     }
60 45
     report(<Info key={`time = ${(Date.now() - begin) / 1000} sec`}></Info>)
61
-    // Timer.clearInterval(it)
62 46
     done()
63 47
   })
64 48
 
@@ -93,7 +77,6 @@ RNTest.config({
93 77
   .then((res) => {
94 78
     try {
95 79
     deb = Date.now()
96
-    // let promise =  RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/raw`, {
97 80
     let promise =  RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
98 81
       Authorization : `Bearer ${DROPBOX_TOKEN}`,
99 82
       'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',

+ 83
- 0
test/test-0.7.0.js Zobrazit soubor

@@ -0,0 +1,83 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import RNFetchBlob from 'react-native-fetch-blob'
4
+import Timer from 'react-timer-mixin'
5
+
6
+import {
7
+  StyleSheet,
8
+  Text,
9
+  View,
10
+  ScrollView,
11
+  CameraRoll,
12
+  Platform,
13
+  Dimensions,
14
+  Image,
15
+} from 'react-native';
16
+
17
+const fs = RNFetchBlob.fs
18
+const { Assert, Comparer, Info, prop } = RNTest
19
+const describe = RNTest.config({
20
+  group : '0.7.0',
21
+  run : true,
22
+  expand : true,
23
+  timeout : 300000000,
24
+})
25
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
26
+const  dirs = RNFetchBlob.fs.dirs
27
+
28
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
29
+
30
+describe('Upload and download large file', (report, done) => {
31
+  let filename = '22mb-dummy-' + Date.now()
32
+  let begin = -1
33
+  let begin2 = -1
34
+  let deb = Date.now()
35
+  RNFetchBlob.config({
36
+    fileCache : true
37
+  })
38
+  .fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
39
+  .progress((now, total) => {
40
+    if(begin === -1)
41
+      begin = Date.now()
42
+    if(Date.now() - deb < 1000)
43
+      return
44
+    deb = Date.now()
45
+    report(<Info uid="200" key="progress">
46
+      <Text>
47
+        {`download ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s)`}
48
+      </Text>
49
+    </Info>)
50
+  })
51
+  .then((res) => {
52
+    try {
53
+    deb = Date.now()
54
+    let promise =  RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
55
+      Authorization : `Bearer ${DROPBOX_TOKEN}`,
56
+      'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
57
+      'Content-Type' : 'application/octet-stream',
58
+    }, RNFetchBlob.wrap(res.path()))
59
+    promise.uploadProgress((now, total) => {
60
+      if(Date.now() - deb < 1000)
61
+        return
62
+      deb = Date.now()
63
+      if(begin2 === -1)
64
+        begin2 = Date.now()
65
+      let speed = Math.floor(now / (Date.now() - begin2))
66
+      report(<Info uid="100"  key="progress">
67
+        <Text>
68
+          {`upload ${now} / ${total} bytes (${speed} kb/s)`}
69
+          {` ${Math.floor((total-now)/speed/1000)} seconds left`}
70
+        </Text>
71
+      </Info>)
72
+    })
73
+    return promise
74
+  } catch(err) { console.log(err) }
75
+  })
76
+  .then((res) => {
77
+    report(<Assert
78
+      key="upload should success without crashing app"
79
+      expect={filename}
80
+      actual={res.json().name}/>)
81
+    done()
82
+  })
83
+})

+ 8
- 7
test/test-init.js Zobrazit soubor

@@ -59,10 +59,11 @@ describe('GET image from server', (report, done) => {
59 59
 
60 60
 
61 61
 require('./test-0.1.x-0.4.x')
62
-// require('./test-0.5.1')
63
-// require('./test-0.5.2')
64
-// require('./test-0.6.0')
65
-// require('./test-0.6.2')
66
-// require('./test-0.6.3')
67
-// require('./test-fs')
68
-// require('./test-android')
62
+require('./test-0.5.1')
63
+require('./test-0.5.2')
64
+require('./test-0.6.0')
65
+require('./test-0.6.2')
66
+require('./test-0.6.3')
67
+require('./test-0.7.0')
68
+require('./test-fs')
69
+require('./test-android')