ソースを参照

Merge branch '0.9.4' into 0.10.0

Ben Hsieh 8 年 前
コミット
6a4cb4af6d
共有6 個のファイルを変更した72 個の追加16 個の削除を含む
  1. 1
    1
      package.json
  2. 4
    5
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
  3. 1
    1
      src/package.json
  4. 1
    8
      src/polyfill/XMLHttpRequest.js
  5. 2
    1
      src/polyfill/XMLHttpRequestEventTarget.js
  6. 63
    0
      test/test-0.9.4.js

+ 1
- 1
package.json ファイルの表示

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "fetchblob-dev",
3
-  "version": "0.9.3",
3
+  "version": "0.9.4",
4 4
   "private": true,
5 5
   "scripts": {
6 6
     "start": "node node_modules/react-native/local-cli/cli.js start",

+ 4
- 5
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java ファイルの表示

@@ -458,9 +458,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
458 458
                     // It uses customized response body which is able to report download progress
459 459
                     // and write response data to destination path.
460 460
                     resp.body().bytes();
461
-                } catch (Exception ignored) {
462
-                    ignored.printStackTrace();
463
-                }
461
+                } catch (Exception ignored) {  }
464 462
                 callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
465 463
                 break;
466 464
             default:
@@ -471,8 +469,9 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
471 469
                 }
472 470
                 break;
473 471
         }
474
-        if(!resp.isSuccessful())
475
-            resp.body().close();
472
+//        if(!resp.isSuccessful())
473
+//            resp.body().close();
474
+        resp.body().close();
476 475
         releaseTaskResource();
477 476
     }
478 477
 

+ 1
- 1
src/package.json ファイルの表示

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-fetch-blob",
3
-  "version": "0.9.3",
3
+  "version": "0.9.4-beta.1",
4 4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5 5
   "main": "index.js",
6 6
   "scripts": {

+ 1
- 8
src/polyfill/XMLHttpRequest.js ファイルの表示

@@ -321,6 +321,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
321 321
     log.debug('XMLHttpRequest done', this._url, resp, this)
322 322
     this._statusText = this._status
323 323
     let responseDataReady = () => {
324
+      log.debug('request done state = 4')
324 325
       this.dispatchEvent('load')
325 326
       this.dispatchEvent('loadend')
326 327
       this._dispatchReadStateChange(XMLHttpRequest.DONE)
@@ -330,14 +331,6 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
330 331
       let info = resp.respInfo || {}
331 332
       log.debug(this._url, info, info.respType)
332 333
       switch(info.respType) {
333
-        case 'json' :
334
-        try{
335
-          this._responseText = resp.text()
336
-          this._response = resp.json()
337
-          responseDataReady()
338
-        } catch(err) {
339
-        }
340
-        break;
341 334
         case 'blob' :
342 335
           resp.blob().then((b) => {
343 336
             this._responseText = resp.text()

+ 2
- 1
src/polyfill/XMLHttpRequestEventTarget.js ファイルの表示

@@ -26,6 +26,7 @@ export default class XMLHttpRequestEventTarget extends EventTarget {
26 26
   }
27 27
 
28 28
   dispatchEvent(event:string, e:Event) {
29
+    log.debug('dispatch event', event, e)
29 30
     super.dispatchEvent(event, e)
30 31
     switch(event) {
31 32
       case 'abort' :
@@ -70,7 +71,7 @@ export default class XMLHttpRequestEventTarget extends EventTarget {
70 71
   }
71 72
 
72 73
   set onload(fn:(e:Event) => void) {
73
-    log.info('set onload')
74
+    log.info('set onload', fn)
74 75
     this._onload = fn
75 76
   }
76 77
 

+ 63
- 0
test/test-0.9.4.js ファイルの表示

@@ -0,0 +1,63 @@
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
+  Platform,
10
+  Dimensions,
11
+  Image,
12
+} from 'react-native';
13
+
14
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
15
+window.Blob = RNFetchBlob.polyfill.Blob
16
+
17
+const fs = RNFetchBlob.fs
18
+const { Assert, Comparer, Info, prop } = RNTest
19
+const describe = RNTest.config({
20
+  group : '0.9.4',
21
+  run : true,
22
+  expand : true,
23
+  timeout : 20000,
24
+})
25
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
26
+const dirs = RNFetchBlob.fs.dirs
27
+
28
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
29
+
30
+describe('issue #105', (report, done) => {
31
+  let tmp = null
32
+  RNFetchBlob
33
+    .config({ fileCache : true })
34
+    .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
35
+    .then((res) => {
36
+      tmp = res.path()
37
+      return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
38
+        'Content-Type' : 'multipart/form-data',
39
+        'Expect' : '100-continue'
40
+      }, [
41
+        { name : 'data', data : 'issue#105 test' },
42
+        { name : 'file', filename : 'github.png', data : RNFetchBlob.wrap(tmp) }
43
+      ])
44
+    })
45
+    .then((res) => {
46
+      done()
47
+    })
48
+})
49
+
50
+describe('issue #106', (report, done) => {
51
+
52
+  fetch('https://rnfb-test-app.firebaseapp.com/6m-json.json')
53
+    .then((res) => {
54
+      console.log('## converted')
55
+      return res.json()
56
+    })
57
+    .then((data) => {
58
+      // console.log(data)
59
+      report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
60
+      done()
61
+    })
62
+
63
+})