No Description

test-0.10.0.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. AsyncStorage,
  13. Image,
  14. } from 'react-native';
  15. const JSONStream = RNFetchBlob.JSONStream
  16. const fs = RNFetchBlob.fs
  17. const { Assert, Comparer, Info, prop } = RNTest
  18. const describe = RNTest.config({
  19. group : '0.10.0',
  20. run : true,
  21. expand : true,
  22. timeout : 20000,
  23. })
  24. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  25. const dirs = RNFetchBlob.fs.dirs
  26. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  27. let begin = Date.now()
  28. // describe('json stream via HTTP', (report, done) => {
  29. //
  30. // let count = 0
  31. // JSONStream(`${TEST_SERVER_URL}/public/json-dummy.json`).node('name', (name) => {
  32. // count++
  33. // if(Date.now() - begin < 100)
  34. // return
  35. // begin = Date.now()
  36. // report(<Info key="report" uid="100">
  37. // <Text>{count} records</Text>
  38. // </Info>)
  39. // done()
  40. // })
  41. //
  42. // })
  43. //
  44. // describe('json stream via fs', (report, done) => {
  45. //
  46. // let fetch2 = new RNFetchBlob.polyfill.Fetch({
  47. // auto : true
  48. // })
  49. // let res = null
  50. // let count = 0
  51. //
  52. // RNFetchBlob.config({
  53. // fileCache : true
  54. // })
  55. // .fetch('GET',`${TEST_SERVER_URL}/public/json-dummy.json`)
  56. // .then((resp) => {
  57. // res = resp
  58. // JSONStream({
  59. // url : RNFetchBlob.wrap(res.path()),
  60. // headers : { bufferSize : 10240 }
  61. // }).node('name', (name) => {
  62. // count++
  63. // if(Date.now() - begin < 100)
  64. // return
  65. // begin = Date.now()
  66. // report(<Info key="report" uid="100">
  67. // <Text>{count} records</Text>
  68. // </Info>)
  69. // done()
  70. // })
  71. // })
  72. // })
  73. //
  74. // describe('issue #102', (report, done) => {
  75. // let tmp = null
  76. // RNFetchBlob.config({ fileCache: true, appendExt : 'png' })
  77. // .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  78. // .then((res) => {
  79. // tmp = res
  80. // RNFetchBlob.ios.previewDocument(res.path())
  81. // return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {},
  82. // [{ name : String(1), data : RNFetchBlob.wrap(res.path()), filename: '#102-test-image.png' }])
  83. // })
  84. // .then((res) => tmp.flush())
  85. // .then(() => {
  86. // done()
  87. // })
  88. //
  89. // })
  90. // describe('#154 Allow passing unparsed response body to error handler ', (report, done) =>{
  91. //
  92. // RNFetchBlob.fetch('get', `${TEST_SERVER_URL}/err-body`)
  93. // .then((res) => {
  94. // console.log(res)
  95. // })
  96. // .catch((err) => {
  97. // console.log(err)
  98. // })
  99. //
  100. // })
  101. //
  102. // describe('cookie test', (report, done) => {
  103. //
  104. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie`)
  105. // .then((res) => {
  106. // return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/xhr-header`)
  107. // })
  108. // .then((res) => {
  109. // console.log(res)
  110. // RNFetchBlob.net.getCookies(`${TEST_SERVER_URL}`)
  111. // .then((cookies) => {
  112. // console.log(cookies)
  113. // })
  114. // })
  115. //
  116. // })
  117. describe('SSL test #159', (report, done) => {
  118. RNFetchBlob.config({
  119. trusty : true
  120. }).fetch('GET', `${TEST_SERVER_URL_SSL}/public/github.png`, {
  121. 'Cache-Control' : 'no-store'
  122. })
  123. .then(res => {
  124. report(<Assert key="trusty request should pass" expect={true} actual={true}/>)
  125. return RNFetchBlob.fetch('GET',`${TEST_SERVER_URL_SSL}/public/github.png`)
  126. })
  127. .catch(e => {
  128. report(<Assert key="non-trusty request should not pass" expect={true} actual={true}/>)
  129. done()
  130. })
  131. })
  132. describe('#162 get free disk space', (report, done) => {
  133. fs.df().then((stat) => {
  134. console.log(stat);
  135. done();
  136. })
  137. })