@@ -13,13 +13,15 @@ import {
13
13
AsyncStorage ,
14
14
Image ,
15
15
} from 'react-native' ;
16
+ window . XMLHttpRequest = RNFetchBlob . polyfill . XMLHttpRequest
17
+ window . Blob = RNFetchBlob . polyfill . Blob
16
18
const JSONStream = RNFetchBlob . JSONStream
17
19
const fs = RNFetchBlob . fs
18
20
const { Assert, Comparer, Info, prop } = RNTest
19
21
const describe = RNTest . config ( {
20
22
group : '0.10.0' ,
21
23
run : true ,
22
- expand : true ,
24
+ expand : false ,
23
25
timeout : 20000 ,
24
26
} )
25
27
const { TEST_SERVER_URL , TEST_SERVER_URL_SSL , FILENAME , DROPBOX_TOKEN , styles } = prop ( )
@@ -72,73 +74,56 @@ describe('json stream via fs', (report, done) => {
72
74
} )
73
75
} )
74
76
} )
75
- //
76
- // describe('issue #102', (report, done) => {
77
- // let tmp = null
78
- // RNFetchBlob.config({ fileCache: true, appendExt : 'png' })
79
- // .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
80
- // .then((res) => {
81
- // tmp = res
82
- // RNFetchBlob.ios.previewDocument(res.path())
83
- // return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {},
84
- // [{ name : String(1), data : RNFetchBlob.wrap(res.path()), filename: '#102-test-image.png' }])
85
- // })
86
- // .then((res) => tmp.flush())
87
- // .then(() => {
88
- // done()
89
- // })
90
- //
91
- // })
92
77
93
- // describe('#154 Allow passing unparsed response body to error handler ', (report, done) =>{
94
- //
95
- // RNFetchBlob.fetch('get', `${TEST_SERVER_URL}/err-body`)
96
- // .then((res) => {
97
- // console.log(res)
98
- // })
99
- // .catch((err) => {
100
- // console.log(err)
101
- // })
102
- //
103
- // })
104
- //
105
- // describe('cookie test', (report, done) => {
106
- //
107
- // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie`)
108
- // .then((res) => {
109
- // return RNFetchBlotesb.fetch('GET', `${TEST_SERVER_URL}/xhr-header`)
110
- // })
111
- // .then((res) => {
112
- // console.log(res)
113
- // RNFetchBlob.net.getCookies(`${TEST_SERVER_URL}`)
114
- // .then((cookies) => {
115
- // console.log(cookies)
116
- // })
117
- // })
118
- //
119
- // })
120
78
121
- // describe('SSL test #159', (report, done) => {
122
- // RNFetchBlob.config({
123
- // trusty : true
124
- // }).fetch('GET', `${TEST_SERVER_URL_SSL}/public/github.png`, {
125
- // 'Cache-Control' : 'no-store'
126
- // })
127
- // .then(res => {
128
- // report(<Assert key="trusty request should pass" expect={true} actual={true}/>)
129
- // return RNFetchBlob.fetch('GET',`${TEST_SERVER_URL_SSL}/public/github.png`)
130
- // })
131
- // .catch(e => {
132
- // report(<Assert key="non-trusty request should not pass" expect={true} actual={true}/>)
133
- // done()
134
- // })
135
- // })
79
+ describe ( 'cookie test' , ( report , done ) => {
80
+ let time = Date . now ( )
81
+ RNFetchBlob . fetch ( 'GET' , `${ TEST_SERVER_URL } /cookie/${ time } ` )
82
+ . then ( ( res ) => RNFetchBlob . net . getCookies ( `${ TEST_SERVER_URL } ` ) )
83
+ . then ( ( cookies ) => {
84
+ let result = / c o o k i e N a m e \= [ ^ ; ] + / . exec ( cookies [ 0 ] )
85
+ console . log ( result , 'cookieName=' + time )
86
+ report ( < Assert key = "cookie should not be empty"
87
+ expect = { 'cookieName=' + time }
88
+ actual = { result [ 0 ] } /> )
89
+ done ( )
90
+ } )
91
+
92
+ } )
136
93
137
- // describe('#162 get free disk space', (report, done) => {
138
- //
139
- // fs.df().then((stat) => {
140
- // console.log(stat);
141
- // done();
142
- // })
143
- //
144
- // })
94
+ describe ( 'SSL test #159' , ( report , done ) => {
95
+ RNFetchBlob . config ( {
96
+ trusty : true
97
+ } )
98
+ . fetch ( 'GET' , `${ TEST_SERVER_URL_SSL } /public/github.png` , {
99
+ 'Cache-Control' : 'no-store'
100
+ } )
101
+ . then ( res => {
102
+ report ( < Assert key = "trusty request should pass" expect = { true } actual = { true } /> )
103
+ return RNFetchBlob . fetch ( 'GET' , `${ TEST_SERVER_URL_SSL } /public/github.png` )
104
+ } )
105
+ . catch ( e => {
106
+ report ( < Assert key = "non-trusty request should not pass" expect = { true } actual = { true } /> )
107
+ done ( )
108
+ } )
109
+ } )
110
+
111
+ describe ( '#171 appendExt verify' , ( report , done ) => {
112
+
113
+ RNFetchBlob . config ( {
114
+ fileCache : true ,
115
+ appendExt : 'png'
116
+ } )
117
+ . fetch ( 'GET' , `${ TEST_SERVER_URL } /public/github.png` , {
118
+ 'Cache-Control' : 'no-store'
119
+ } )
120
+ . then ( res => {
121
+ report ( < Assert key = "extension appended to tmp path" actual = { / .p n g $ / . test ( res . path ( ) ) } expect = { true } /> )
122
+ return fs . stat ( res . path ( ) )
123
+ } )
124
+ . then ( stat => {
125
+ report ( < Assert key = "verify the file existence" expect = "23975" actual = { stat . size } /> )
126
+ done ( )
127
+ } )
128
+
129
+ } )
0 commit comments