Skip to content

Commit 0060439

Browse files
committed
Add test case for #263 parallel request mixed issue
1 parent edd5956 commit 0060439

File tree

1 file changed

+77
-53
lines changed

1 file changed

+77
-53
lines changed

test/test-0.10.3.js

+77-53
Original file line numberDiff line numberDiff line change
@@ -31,61 +31,85 @@ const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles }
3131
const dirs = RNFetchBlob.fs.dirs
3232
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
3333
let begin = Date.now()
34+
//
35+
// describe('#230 #249 cookies manipulation', (report, done) => {
36+
//
37+
// RNFetchBlob
38+
// .fetch('GET', `${TEST_SERVER_URL}/cookie/249230`)
39+
// .then((res) => RNFetchBlob.net.getCookies())
40+
// .then((cookies) => {
41+
// console.log(cookies)
42+
// report(<Assert
43+
// key="should set 10 cookies"
44+
// expect={10}
45+
// actual={cookies['localhost'].length}/>)
46+
// return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
47+
// })
48+
// .then((res) => {
49+
// console.log(res.data)
50+
// let cookies = String(res.data).split(';')
51+
// report(<Assert
52+
// key="should send 10 cookies"
53+
// expect={10}
54+
// actual={cookies.length}/>)
55+
// return RNFetchBlob.net.removeCookies()
56+
// })
57+
// .then(() => RNFetchBlob.net.getCookies('localhost'))
58+
// .then((cookies) => {
59+
// report(<Assert
60+
// key="should have no cookies"
61+
// expect={undefined}
62+
// actual={cookies['localhost']}/>)
63+
// return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
64+
// })
65+
// .then((res) => {
66+
// console.log(res.data)
67+
// let cookies = String(res.data).split(';')
68+
// cookies = _.reject(cookies, r => r.length < 2)
69+
// report(<Assert
70+
// key="should send no cookies"
71+
// expect={0}
72+
// actual={cookies.length}/>)
73+
// done()
74+
// })
75+
//
76+
// })
77+
//
78+
// describe('#254 IOS fs.stat lastModified date correction', (report, done) => {
79+
//
80+
// let path = dirs.DocumentDir + '/temp' + Date.now()
81+
// fs.createFile(path, 'hello', 'utf8' )
82+
// .then(() => fs.stat(path))
83+
// .then((stat) => {
84+
// console.log(stat)
85+
// let p = stat.lastModified / Date.now()
86+
// report(<Assert key="date is correct" expect={true} actual={ p< 1.05 && p > 0.95}/>)
87+
// done()
88+
// })
89+
//
90+
// })
3491

35-
36-
describe('#230 #249 cookies manipulation', (report, done) => {
37-
38-
RNFetchBlob
39-
.fetch('GET', `${TEST_SERVER_URL}/cookie/249230`)
40-
.then((res) => RNFetchBlob.net.getCookies())
41-
.then((cookies) => {
42-
console.log(cookies)
43-
report(<Assert
44-
key="should set 10 cookies"
45-
expect={10}
46-
actual={cookies['localhost'].length}/>)
47-
return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
48-
})
49-
.then((res) => {
50-
console.log(res.data)
51-
let cookies = String(res.data).split(';')
52-
report(<Assert
53-
key="should send 10 cookies"
54-
expect={10}
55-
actual={cookies.length}/>)
56-
return RNFetchBlob.net.removeCookies()
57-
})
58-
.then(() => RNFetchBlob.net.getCookies('localhost'))
59-
.then((cookies) => {
60-
report(<Assert
61-
key="should have no cookies"
62-
expect={undefined}
63-
actual={cookies['localhost']}/>)
64-
return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
65-
})
66-
.then((res) => {
67-
console.log(res.data)
68-
let cookies = String(res.data).split(';')
69-
cookies = _.reject(cookies, r => r.length < 2)
70-
report(<Assert
71-
key="should send no cookies"
72-
expect={0}
73-
actual={cookies.length}/>)
92+
describe('#263 parallel request', (report, done) => {
93+
let urls = [
94+
`${TEST_SERVER_URL}/public/1mb-dummy`,
95+
`${TEST_SERVER_URL}/public/2mb-dummy`,
96+
`${TEST_SERVER_URL}/public/404`
97+
]
98+
let size = [1000000, 1310720, 23]
99+
let asserts = []
100+
new Promise
101+
.all(urls.map((url) => RNFetchBlob.fetch('GET', url)))
102+
.then((results) => {
103+
_.each(results, (r, i) => {
104+
report(
105+
<Assert key={`redirect URL ${i} should be correct`}
106+
expect={urls[i]}
107+
actual={r.info().redirects[0]}/>)
108+
report(<Assert key={`content ${i} should be correct`}
109+
expect={size[i]}
110+
actual={r.data.length}/>)
111+
})
74112
done()
75113
})
76114

77115
})
78-
79-
describe('#254 IOS fs.stat lastModified date correction', (report, done) => {
80-
81-
let path = dirs.DocumentDir + '/temp' + Date.now()
82-
fs.createFile(path, 'hello', 'utf8' )
83-
.then(() => fs.stat(path))
84-
.then((stat) => {
85-
console.log(stat)
86-
let p = stat.lastModified / Date.now()
87-
report(<Assert key="date is correct" expect={true} actual={ p< 1.05 && p > 0.95}/>)
88-
done()
89-
})
90-
91-
})

0 commit comments

Comments
 (0)