@@ -27,56 +27,56 @@ const dirs = RNFetchBlob.fs.dirs
27
27
28
28
let prefix = ( ( Platform . OS === 'android' ) ? 'file://' : '' )
29
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
- // })
64
- //
65
- // describe('issue #111 get redirect destination', (report, done) => {
66
- // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67
- // .then((res) => {
68
- // report(
69
- // <Assert key="redirect history should tracable"
70
- // expect={2}
71
- // actual={res.info().redirects.length}/>,
72
- // <Assert key="redirect history verify"
73
- // expect={[`${TEST_SERVER_URL}/redirect`, `${TEST_SERVER_URL}/public/github.png`] }
74
- // comparer={Comparer.equalToArray}
75
- // actual={res.info().redirects}/>,
76
- // )
77
- // done()
78
- // })
79
- // })
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
+ } )
64
+
65
+ describe ( 'issue #111 get redirect destination' , ( report , done ) => {
66
+ RNFetchBlob . fetch ( 'GET' , `${ TEST_SERVER_URL } /redirect` )
67
+ . then ( ( res ) => {
68
+ report (
69
+ < Assert key = "redirect history should tracable"
70
+ expect = { 2 }
71
+ actual = { res . info ( ) . redirects . length } /> ,
72
+ < Assert key = "redirect history verify"
73
+ expect = { [ `${ TEST_SERVER_URL } /redirect` , `${ TEST_SERVER_URL } /public/github.png` ] }
74
+ comparer = { Comparer . equalToArray }
75
+ actual = { res . info ( ) . redirects } /> ,
76
+ )
77
+ done ( )
78
+ } )
79
+ } )
80
80
81
81
describe ( 'chunked encoding option test' , ( report , done ) => {
82
82
@@ -103,3 +103,53 @@ describe('chunked encoding option test', (report, done) => {
103
103
done ( )
104
104
} )
105
105
} )
106
+
107
+ describe ( '#118 ' , ( report , done ) => {
108
+ let cache = null
109
+ let size = 0
110
+ let tick = Date . now ( )
111
+ let start = - 1
112
+ let count = 0
113
+
114
+ RNFetchBlob . config ( { fileCache : true } )
115
+ . fetch ( 'GET' , `${ TEST_SERVER_URL } /public/22mb-dummy` )
116
+ . then ( ( res ) => {
117
+ cache = res . path ( )
118
+ return fs . readStream ( cache , 'utf8' , 102400 )
119
+ } )
120
+ // .then((res) => {
121
+ // cache = res.path()
122
+ // return fs.readFile(cache, 'utf8')
123
+ // })
124
+ // .then(() => {
125
+ // report(<Info key="good" />)
126
+ // done()
127
+ // fs.unlink(cache)
128
+ // })
129
+ . then ( ( stream ) => {
130
+ stream . open ( )
131
+ start = Date . now ( )
132
+ stream . onData ( ( chunk ) => {
133
+ count ++
134
+ size += chunk . length
135
+ if ( Date . now ( ) - tick > 500 ) {
136
+ tick = Date . now ( )
137
+ report (
138
+ < Info key = "size" uid = "100" > < Text > { size } bytes read</ Text > </ Info > )
139
+ }
140
+ } )
141
+ stream . onEnd ( ( ) => {
142
+ report (
143
+ < Info key = "size" uid = "100" > < Text > { size } bytes read</ Text > </ Info > ,
144
+ < Info key = "elapsed" > < Text > { Date . now ( ) - start } ms</ Text > </ Info > ,
145
+ < Info key = "events" > < Text > { count } times</ Text > </ Info > ,
146
+ < Assert key = "JS thread is not blocked" expect = { true } actual = { true } /> , )
147
+ fs . stat ( cache ) . then ( ( stat ) => {
148
+ report (
149
+ < Info key = "info" > < Text > { JSON . stringify ( stat ) } </ Text > </ Info > )
150
+ fs . unlink ( cache )
151
+ } )
152
+ } )
153
+ } )
154
+
155
+ } )
0 commit comments