Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 8c132ed

Browse files
committed
Add 0.10.1 test case
1 parent 5da0113 commit 8c132ed

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

test/test-0.10.1.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
Linking,
10+
Platform,
11+
Dimensions,
12+
BackAndroid,
13+
AsyncStorage,
14+
Image,
15+
} from 'react-native';
16+
17+
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
18+
window.Blob = RNFetchBlob.polyfill.Blob
19+
20+
const JSONStream = RNFetchBlob.JSONStream
21+
const fs = RNFetchBlob.fs
22+
const { Assert, Comparer, Info, prop } = RNTest
23+
const describe = RNTest.config({
24+
group : '0.10.1',
25+
run : true,
26+
expand : true,
27+
timeout : 20000,
28+
})
29+
const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
30+
const dirs = RNFetchBlob.fs.dirs
31+
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
32+
let begin = Date.now()
33+
34+
describe('#177 multipart upload event only triggers once', (report, done) => {
35+
36+
try{
37+
let localFile = null
38+
let filename = 'dummy-'+Date.now()
39+
RNFetchBlob.config({
40+
fileCache : true
41+
})
42+
.fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
43+
.then((res) => {
44+
localFile = res.path()
45+
return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
46+
'Content-Type' : 'multipart/form-data',
47+
}, [
48+
{ name : 'test-img', filename : filename, data: 'RNFetchBlob-file://' + localFile},
49+
{ name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
50+
{ name : 'field1', data : 'hello !!'},
51+
{ name : 'field2', data : 'hello2 !!'}
52+
])
53+
.uploadProgress({ interval : 100 },(now, total) => {
54+
console.log(now/total)
55+
})
56+
})
57+
.then((resp) => {
58+
resp = resp.json()
59+
report(
60+
<Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
61+
<Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
62+
)
63+
return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
64+
})
65+
.then((resp) => {
66+
report(<Info key="uploaded image">
67+
<Image
68+
style={styles.image}
69+
source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
70+
</Info>)
71+
done()
72+
})
73+
} catch(err) {
74+
console.log(err)
75+
}
76+
})

test/test-init.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const { Assert, Comparer, Info, prop } = RNTest
1818
// test environment variables
1919

2020
prop('FILENAME', `${Platform.OS}-0.10.0-${Date.now()}.png`)
21-
prop('TEST_SERVER_URL', 'http://localhost:8123')
22-
prop('TEST_SERVER_URL_SSL', 'https://localhost:8124')
23-
// prop('TEST_SERVER_URL', 'http://192.168.0.12:8123')
24-
// prop('TEST_SERVER_URL_SSL', 'https://192.168.0.12:8124')
21+
// prop('TEST_SERVER_URL', 'http://localhost:8123')
22+
// prop('TEST_SERVER_URL_SSL', 'https://localhost:8124')
23+
prop('TEST_SERVER_URL', 'http://192.168.17.185:8123')
24+
prop('TEST_SERVER_URL_SSL', 'https://192.168.17.185:8124')
2525
prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
2626
prop('styles', {
2727
image : {
@@ -73,7 +73,8 @@ describe('GET image from server', (report, done) => {
7373
// require('./test-0.9.4')
7474
// require('./test-0.9.5')
7575
// require('./test-0.9.6')
76-
require('./test-0.10.0')
76+
// require('./test-0.10.0')
77+
require('./test-0.10.1')
7778
// require('./test-background.js')
7879
// require('./test-stream')
7980
// require('./test-fetch')

0 commit comments

Comments
 (0)