No Description

test-0.10.0.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  17. window.Blob = RNFetchBlob.polyfill.Blob
  18. const JSONStream = RNFetchBlob.JSONStream
  19. const fs = RNFetchBlob.fs
  20. const { Assert, Comparer, Info, prop } = RNTest
  21. const describe = RNTest.config({
  22. group : '0.10.0',
  23. run : true,
  24. expand : false,
  25. timeout : 20000,
  26. })
  27. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  28. const dirs = RNFetchBlob.fs.dirs
  29. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  30. let begin = Date.now()
  31. describe('json stream via HTTP', (report, done) => {
  32. let count = 0
  33. JSONStream(`${TEST_SERVER_URL}/public/json-dummy.json`).node('name', (name) => {
  34. count++
  35. if(Date.now() - begin < 100)
  36. return
  37. begin = Date.now()
  38. report(<Info key="report" uid="100">
  39. <Text>{count} records</Text>
  40. </Info>)
  41. done()
  42. })
  43. })
  44. describe('json stream via fs', (report, done) => {
  45. let fetch2 = new RNFetchBlob.polyfill.Fetch({
  46. auto : true
  47. })
  48. let res = null
  49. let count = 0
  50. RNFetchBlob.config({
  51. fileCache : true
  52. })
  53. .fetch('GET',`${TEST_SERVER_URL}/public/json-dummy.json`)
  54. .then((resp) => {
  55. res = resp
  56. JSONStream({
  57. url : RNFetchBlob.wrap(res.path()),
  58. headers : { bufferSize : 10240 }
  59. }).node('name', (name) => {
  60. count++
  61. if(Date.now() - begin < 100)
  62. return
  63. begin = Date.now()
  64. report(<Info key="report" uid="100">
  65. <Text>{count} records</Text>
  66. </Info>)
  67. done()
  68. })
  69. })
  70. })
  71. describe('cookie test', (report, done) => {
  72. let time = Date.now()
  73. RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie/${time}`)
  74. .then((res) => RNFetchBlob.net.getCookies(`${TEST_SERVER_URL}`))
  75. .then((cookies) => {
  76. let result = /cookieName\=[^;]+/.exec(cookies[0])
  77. console.log(result, 'cookieName=' + time)
  78. report(<Assert key="cookie should not be empty"
  79. expect={'cookieName=' + time}
  80. actual={result[0]}/>)
  81. done()
  82. })
  83. })
  84. describe('SSL test #159', (report, done) => {
  85. RNFetchBlob.config({
  86. trusty : true
  87. })
  88. .fetch('GET', `${TEST_SERVER_URL_SSL}/public/github.png`, {
  89. 'Cache-Control' : 'no-store'
  90. })
  91. .then(res => {
  92. report(<Assert key="trusty request should pass" expect={true} actual={true}/>)
  93. return RNFetchBlob.fetch('GET',`${TEST_SERVER_URL_SSL}/public/github.png`)
  94. })
  95. .catch(e => {
  96. report(<Assert key="non-trusty request should not pass" expect={true} actual={true}/>)
  97. done()
  98. })
  99. })
  100. describe('#171 appendExt verify', (report, done) => {
  101. RNFetchBlob.config({
  102. fileCache : true,
  103. appendExt : 'png'
  104. })
  105. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
  106. 'Cache-Control' : 'no-store'
  107. })
  108. .then(res => {
  109. report(<Assert key="extension appended to tmp path" actual={/.png$/.test(res.path())} expect={true}/>)
  110. return fs.stat(res.path())
  111. })
  112. .then(stat => {
  113. report(<Assert key="verify the file existence" expect="23975" actual={stat.size} />)
  114. done()
  115. })
  116. })