@@ -13,13 +13,15 @@ import {
1313 AsyncStorage ,
1414 Image ,
1515} from 'react-native' ;
16+ window . XMLHttpRequest = RNFetchBlob . polyfill . XMLHttpRequest
17+ window . Blob = RNFetchBlob . polyfill . Blob
1618const JSONStream = RNFetchBlob . JSONStream
1719const fs = RNFetchBlob . fs
1820const { Assert, Comparer, Info, prop } = RNTest
1921const describe = RNTest . config ( {
2022 group : '0.10.0' ,
2123 run : true ,
22- expand : true ,
24+ expand : false ,
2325 timeout : 20000 ,
2426} )
2527const { TEST_SERVER_URL , TEST_SERVER_URL_SSL , FILENAME , DROPBOX_TOKEN , styles } = prop ( )
@@ -72,73 +74,56 @@ describe('json stream via fs', (report, done) => {
7274 } )
7375 } )
7476} )
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- // })
9277
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- // })
12078
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+ } )
13693
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