Nenhuma descrição

test-0.10.0.js 3.6KB

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