|
@@ -27,82 +27,82 @@ 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
|
|
-// })
|
80
|
|
-//
|
81
|
|
-// describe('chunked encoding option test', (report, done) => {
|
82
|
|
-//
|
83
|
|
-// let path = null
|
84
|
|
-// let base64 = null
|
85
|
|
-//
|
86
|
|
-// RNFetchBlob
|
87
|
|
-// // .config({ fileCache : true })
|
88
|
|
-// .fetch('GET', `${TEST_SERVER_URL}/public/1600k-img-dummy.jpg`)
|
89
|
|
-// .then((res) => {
|
90
|
|
-// base64 = res.base64()
|
91
|
|
-// return RNFetchBlob
|
92
|
|
-// .fetch('POST', `${TEST_SERVER_URL}/upload`, {
|
93
|
|
-// 'Content-Type' : 'application/octet-stream;BASE64'
|
94
|
|
-// }, base64)
|
95
|
|
-// })
|
96
|
|
-// .then((res) => {
|
97
|
|
-// let headers = res.info().headers
|
98
|
|
-// console.log(res.text())
|
99
|
|
-// report(<Assert key="request should not use chunked encoding"
|
100
|
|
-// expect={undefined}
|
101
|
|
-// actual={headers['transfer-encoding']}/>)
|
102
|
|
-// fs.unlink(path)
|
103
|
|
-// done()
|
104
|
|
-// })
|
105
|
|
-// })
|
|
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
|
+
|
|
81
|
+describe('chunked encoding option test', (report, done) => {
|
|
82
|
+
|
|
83
|
+ let path = null
|
|
84
|
+ let base64 = null
|
|
85
|
+
|
|
86
|
+ RNFetchBlob
|
|
87
|
+ // .config({ fileCache : true })
|
|
88
|
+ .fetch('GET', `${TEST_SERVER_URL}/public/1600k-img-dummy.jpg`)
|
|
89
|
+ .then((res) => {
|
|
90
|
+ base64 = res.base64()
|
|
91
|
+ return RNFetchBlob
|
|
92
|
+ .fetch('POST', `${TEST_SERVER_URL}/upload`, {
|
|
93
|
+ 'Content-Type' : 'application/octet-stream;BASE64'
|
|
94
|
+ }, base64)
|
|
95
|
+ })
|
|
96
|
+ .then((res) => {
|
|
97
|
+ let headers = res.info().headers
|
|
98
|
+ console.log(res.text())
|
|
99
|
+ report(<Assert key="request should not use chunked encoding"
|
|
100
|
+ expect={undefined}
|
|
101
|
+ actual={headers['transfer-encoding']}/>)
|
|
102
|
+ fs.unlink(path)
|
|
103
|
+ done()
|
|
104
|
+ })
|
|
105
|
+})
|
106
|
106
|
|
107
|
107
|
describe('#118 readStream performance prepare the file', (report, done) => {
|
108
|
108
|
let cache = null
|
|
@@ -117,7 +117,7 @@ describe('#118 readStream performance prepare the file', (report, done) => {
|
117
|
117
|
report(<Info key="preparation complete"><Text>start in 3 seconds</Text></Info>)
|
118
|
118
|
cache = res.path()
|
119
|
119
|
setTimeout(() => {
|
120
|
|
- fs.readStream(cache, 'utf8', 102400)
|
|
120
|
+ fs.readStream(cache, 'utf8', 1024000)
|
121
|
121
|
.then((stream) => {
|
122
|
122
|
stream.open()
|
123
|
123
|
start = Date.now()
|
|
@@ -148,28 +148,28 @@ describe('#118 readStream performance prepare the file', (report, done) => {
|
148
|
148
|
})
|
149
|
149
|
})
|
150
|
150
|
|
151
|
|
-// describe('issue #120 upload progress should work when sending body as-is', (report, done) => {
|
152
|
|
-//
|
153
|
|
-// let data = RNTest.prop('image')
|
154
|
|
-// let tick = 0
|
155
|
|
-//
|
156
|
|
-// let task = RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
157
|
|
-// Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
158
|
|
-// 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
|
159
|
|
-// 'Content-Type' : 'text/plain; charset=dropbox-cors-hack',
|
160
|
|
-// }, data)
|
161
|
|
-//
|
162
|
|
-// task.uploadProgress((current, total) => {
|
163
|
|
-// tick ++
|
164
|
|
-// })
|
165
|
|
-// .then((res) => {
|
166
|
|
-// let resp = res.json()
|
167
|
|
-// report(
|
168
|
|
-// <Info key="viewer"><Text>{JSON.stringify(resp)}</Text></Info>,
|
169
|
|
-// <Assert key="event should be triggered"
|
170
|
|
-// expect={tick}
|
171
|
|
-// comparer={Comparer.greater} actual={0}/>)
|
172
|
|
-// done()
|
173
|
|
-// })
|
174
|
|
-//
|
175
|
|
-// })
|
|
151
|
+describe('issue #120 upload progress should work when sending body as-is', (report, done) => {
|
|
152
|
+
|
|
153
|
+ let data = RNTest.prop('image')
|
|
154
|
+ let tick = 0
|
|
155
|
+
|
|
156
|
+ let task = RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
|
157
|
+ Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
|
158
|
+ 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
|
|
159
|
+ 'Content-Type' : 'text/plain; charset=dropbox-cors-hack',
|
|
160
|
+ }, data)
|
|
161
|
+
|
|
162
|
+ task.uploadProgress((current, total) => {
|
|
163
|
+ tick ++
|
|
164
|
+ })
|
|
165
|
+ .then((res) => {
|
|
166
|
+ let resp = res.json()
|
|
167
|
+ report(
|
|
168
|
+ <Info key="viewer"><Text>{JSON.stringify(resp)}</Text></Info>,
|
|
169
|
+ <Assert key="event should be triggered"
|
|
170
|
+ expect={tick}
|
|
171
|
+ comparer={Comparer.greater} actual={0}/>)
|
|
172
|
+ done()
|
|
173
|
+ })
|
|
174
|
+
|
|
175
|
+})
|