Ben Hsieh 7 anos atrás
pai
commit
e1207b89d3
4 arquivos alterados com 90 adições e 26 exclusões
  1. 2
    2
      src/scripts/prelink.js
  2. 1
    1
      test/.babelrc
  3. 69
    6
      test/test-0.10.0.js
  4. 18
    17
      test/test-init.js

+ 2
- 2
src/scripts/prelink.js Ver arquivo

@@ -3,10 +3,10 @@ var fs = require('fs');
3 3
 var MANIFEST_PATH = process.cwd() + '/android/app/src/main/AndroidManifest.xml';
4 4
 var PACKAGE_JSON = process.cwd() + '/package.json';
5 5
 
6
-var hasNecessaryFile = fs.existsSync(MANIFEST_PATH) && fs.existsSync(MANIFEST_PATH);
6
+var hasNecessaryFile = fs.existsSync(MANIFEST_PATH) && fs.existsSync(PACKAGE_JSON);
7 7
 
8 8
 if (!hasNecessaryFile) {
9
-  throw 'RNFetchBlob could not found link Android automatically, some files could not be found.'
9
+  throw 'RNFetchBlob could not link Android automatically, some files could not be found.'
10 10
 }
11 11
 
12 12
 var package = JSON.parse(fs.readFileSync(PACKAGE_JSON));

+ 1
- 1
test/.babelrc Ver arquivo

@@ -12,5 +12,5 @@
12 12
       { "src": "./node_modules/react-native-fetch-blob/node-polyfill/stream.js", "expose": "stream" }
13 13
     ]]
14 14
   ],
15
-  "extends": "./node_modules/react-native/packager/react-packager/rn-babelrc.json",
15
+  "extends": "./node_modules/react-native/packager/react-packager/rn-babelrc.json"
16 16
 }

+ 69
- 6
test/test-0.10.0.js Ver arquivo

@@ -11,12 +11,12 @@ import {
11 11
   Image,
12 12
 } from 'react-native';
13 13
 
14
-window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
15
-window.Blob = RNFetchBlob.polyfill.Blob
16
-window.fetch = new RNFetchBlob.polyfill.Fetch({
17
-  auto : true,
18
-  binaryContentTypes : ['image/', 'video/', 'audio/']
19
-}).build()
14
+// window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
15
+// window.Blob = RNFetchBlob.polyfill.Blob
16
+// window.fetch = new RNFetchBlob.polyfill.Fetch({
17
+//   auto : true,
18
+//   binaryContentTypes : ['image/', 'video/', 'audio/']
19
+// }).build()
20 20
 
21 21
 const fs = RNFetchBlob.fs
22 22
 const { Assert, Comparer, Info, prop } = RNTest
@@ -30,3 +30,66 @@ const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles }
30 30
 const dirs = RNFetchBlob.fs.dirs
31 31
 
32 32
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
33
+
34
+describe('test', (report, done) => {
35
+
36
+  console.log('start')
37
+
38
+  let image = RNTest.prop('image')
39
+  let form = new FormData()
40
+  form.append("FormData", true)
41
+  form.append("access_token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjU3YjgyZGQ2MTEwZDcwYmEwYjUxZjM5YyIsImlzTWVkaWMiOnRydWUsImlhdCI6MTQ3MTY4ODE1MiwiZXhwIjoxNDcxNzA2MTUyfQ.gPeql5g66Am4Txl1WqnbvOWJaD8srTK_6vihOJ6kFbY")
42
+  form.append("Content-Type", "image/jpg")
43
+  form.append('image', {
44
+    uri : `data:image/png;base64, ${image}`,
45
+    type : 'image/png'
46
+  })
47
+
48
+  let xhr = new XMLHttpRequest()
49
+  xhr.open('post', `${TEST_SERVER_URL}/upload-form`)
50
+  xhr.send(form)
51
+  console.log(form)
52
+  xhr.onerror = function(e) {
53
+    console.log('err', e)
54
+  }
55
+  xhr.onreadystatechange = function() {
56
+    console.log('changed')
57
+    if(this.readyState === this.DONE) {
58
+      console.log(this.response)
59
+    }
60
+  }
61
+  // fetch(`${TEST_SERVER_URL}/upload-form`, {
62
+  //   method : 'POST',
63
+  //   body : form
64
+  // })
65
+  // .then((res) => res.text())
66
+  // .then((data) => {
67
+  //   console.log(data)
68
+  // })
69
+
70
+  // let filename = 'test-from-storage-img-'+Date.now()+'.png'
71
+  // RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
72
+  //     'Content-Type' : 'multipart/form-data',
73
+  //   }, [
74
+  //     { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
75
+  //     { name : 'field1', data : 'hello !!'},
76
+  //     { name : 'field2', data : 'hello2 !!'}
77
+  //   ])
78
+  // .then((resp) => {
79
+  //   resp = resp.json()
80
+  //   report(
81
+  //     <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
82
+  //     <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
83
+  //   )
84
+  //   return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
85
+  // })
86
+  // .then((resp) => {
87
+  //   report(<Info key="uploaded image">
88
+  //     <Image
89
+  //       style={styles.image}
90
+  //       source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
91
+  //   </Info>)
92
+  //   done()
93
+  // })
94
+
95
+})

+ 18
- 17
test/test-init.js Ver arquivo

@@ -18,8 +18,8 @@ const { Assert, Comparer, Info, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 prop('FILENAME', `${Platform.OS}-0.8.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://192.168.0.11:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://192.168.0.11:8124')
21
+prop('TEST_SERVER_URL', 'http://192.168.0.12:8123')
22
+prop('TEST_SERVER_URL_SSL', 'https://192.168.0.12:8124')
23 23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24 24
 prop('styles', {
25 25
   image : {
@@ -59,20 +59,21 @@ describe('GET image from server', (report, done) => {
59 59
 })
60 60
 
61 61
 
62
-require('./test-0.1.x-0.4.x')
63
-require('./test-0.5.1')
64
-require('./test-0.5.2')
65
-require('./test-0.6.0')
66
-require('./test-0.6.2')
67
-require('./test-0.7.0')
68
-require('./test-0.8.0')
69
-require('./test-0.9.0')
70
-require('./test-0.9.2')
71
-require('./test-fetch')
72
-require('./test-fs')
73
-require('./test-xmlhttp')
74
-require('./test-blob')
75
-require('./test-firebase')
76
-require('./test-android')
62
+// require('./test-0.1.x-0.4.x')
63
+// require('./test-0.5.1')
64
+// require('./test-0.5.2')
65
+// require('./test-0.6.0')
66
+// require('./test-0.6.2')
67
+// require('./test-0.7.0')
68
+// require('./test-0.8.0')
69
+// require('./test-0.9.0')
70
+// require('./test-0.9.2')
71
+require('./test-0.10.0')
72
+// require('./test-fetch')
73
+// require('./test-fs')
74
+// require('./test-xmlhttp')
75
+// require('./test-blob')
76
+// require('./test-firebase')
77
+// require('./test-android')
77 78
 // require('./test-stress')
78 79
 // require('./benchmark')