Bladeren bron

Add 0.10.1 test case

Ben Hsieh 8 jaren geleden
bovenliggende
commit
8c132edd61
2 gewijzigde bestanden met toevoegingen van 82 en 5 verwijderingen
  1. 76
    0
      test/test-0.10.1.js
  2. 6
    5
      test/test-init.js

+ 76
- 0
test/test-0.10.1.js Bestand weergeven

@@ -0,0 +1,76 @@
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
+  BackAndroid,
13
+  AsyncStorage,
14
+  Image,
15
+} from 'react-native';
16
+
17
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
18
+window.Blob = RNFetchBlob.polyfill.Blob
19
+
20
+const JSONStream = RNFetchBlob.JSONStream
21
+const fs = RNFetchBlob.fs
22
+const { Assert, Comparer, Info, prop } = RNTest
23
+const describe = RNTest.config({
24
+  group : '0.10.1',
25
+  run : true,
26
+  expand : true,
27
+  timeout : 20000,
28
+})
29
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
30
+const dirs = RNFetchBlob.fs.dirs
31
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
32
+let begin = Date.now()
33
+
34
+describe('#177 multipart upload event only triggers once', (report, done) => {
35
+
36
+  try{
37
+    let localFile = null
38
+    let filename = 'dummy-'+Date.now()
39
+    RNFetchBlob.config({
40
+      fileCache : true
41
+    })
42
+    .fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
43
+    .then((res) => {
44
+      localFile = res.path()
45
+      return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
46
+          'Content-Type' : 'multipart/form-data',
47
+        }, [
48
+          { name : 'test-img', filename : filename, data: 'RNFetchBlob-file://' + localFile},
49
+          { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
50
+          { name : 'field1', data : 'hello !!'},
51
+          { name : 'field2', data : 'hello2 !!'}
52
+        ])
53
+        .uploadProgress({ interval : 100 },(now, total) => {
54
+          console.log(now/total)
55
+        })
56
+    })
57
+    .then((resp) => {
58
+      resp = resp.json()
59
+      report(
60
+        <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
61
+        <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
62
+      )
63
+      return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
64
+    })
65
+    .then((resp) => {
66
+      report(<Info key="uploaded image">
67
+        <Image
68
+          style={styles.image}
69
+          source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
70
+      </Info>)
71
+      done()
72
+    })
73
+  } catch(err) {
74
+    console.log(err)
75
+  }
76
+})

+ 6
- 5
test/test-init.js Bestand weergeven

@@ -18,10 +18,10 @@ const { Assert, Comparer, Info, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 prop('FILENAME', `${Platform.OS}-0.10.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://localhost:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://localhost:8124')
23
-// prop('TEST_SERVER_URL', 'http://192.168.0.12:8123')
24
-// prop('TEST_SERVER_URL_SSL', 'https://192.168.0.12:8124')
21
+// prop('TEST_SERVER_URL', 'http://localhost:8123')
22
+// prop('TEST_SERVER_URL_SSL', 'https://localhost:8124')
23
+prop('TEST_SERVER_URL', 'http://192.168.17.185:8123')
24
+prop('TEST_SERVER_URL_SSL', 'https://192.168.17.185:8124')
25 25
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
26 26
 prop('styles', {
27 27
   image : {
@@ -73,7 +73,8 @@ describe('GET image from server', (report, done) => {
73 73
 // require('./test-0.9.4')
74 74
 // require('./test-0.9.5')
75 75
 // require('./test-0.9.6')
76
-require('./test-0.10.0')
76
+// require('./test-0.10.0')
77
+require('./test-0.10.1')
77 78
 // require('./test-background.js')
78 79
 // require('./test-stream')
79 80
 // require('./test-fetch')