No Description

test-0.9.4.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Platform,
  10. Dimensions,
  11. Image,
  12. } from 'react-native';
  13. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  14. window.Blob = RNFetchBlob.polyfill.Blob
  15. const fs = RNFetchBlob.fs
  16. const { Assert, Comparer, Info, prop } = RNTest
  17. const describe = RNTest.config({
  18. group : '0.9.4',
  19. run : true,
  20. expand : true,
  21. timeout : 20000,
  22. })
  23. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  24. const dirs = RNFetchBlob.fs.dirs
  25. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  26. // describe('issue #105', (report, done) => {
  27. // let tmp = null
  28. // RNFetchBlob
  29. // .config({ fileCache : true })
  30. // .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  31. // .then((res) => {
  32. // tmp = res.path()
  33. // return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
  34. // 'Content-Type' : 'multipart/form-data',
  35. // 'Expect' : '100-continue'
  36. // }, [
  37. // { name : 'data', data : 'issue#105 test' },
  38. // { name : 'file', filename : 'github.png', data : RNFetchBlob.wrap(tmp) }
  39. // ])
  40. // })
  41. // .then((res) => {
  42. // done()
  43. // })
  44. // })
  45. //
  46. // describe('issue #106', (report, done) => {
  47. //
  48. // fetch('https://rnfb-test-app.firebaseapp.com/6m-json.json')
  49. // .then((res) => {
  50. // console.log('## converted')
  51. // return res.json()
  52. // })
  53. // .then((data) => {
  54. // // console.log(data)
  55. // report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
  56. // done()
  57. // })
  58. //
  59. // })
  60. //
  61. // describe('issue #111 get redirect destination', (report, done) => {
  62. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
  63. // .then((res) => {
  64. // report(
  65. // <Assert key="redirect history should tracable"
  66. // expect={2}
  67. // actual={res.info().redirects.length}/>,
  68. // <Assert key="redirect history verify"
  69. // expect={[`${TEST_SERVER_URL}/redirect`, `${TEST_SERVER_URL}/public/github.png`]}
  70. // comparer={Comparer.equalToArray}
  71. // actual={res.info().redirects}/>,
  72. // )
  73. // done()
  74. // })
  75. // })
  76. describe('chunked encoding option test', (report, done) => {
  77. let path = null
  78. let base64 = null
  79. RNFetchBlob
  80. // .config({ fileCache : true })
  81. .fetch('GET', `${TEST_SERVER_URL}/public/1600k-img-dummy.jpg`)
  82. .then((res) => {
  83. base64 = res.base64()
  84. return RNFetchBlob
  85. .fetch('POST', `${TEST_SERVER_URL}/upload`, {
  86. 'Content-Type' : 'application/octet-stream;BASE64'
  87. }, base64)
  88. })
  89. .then((res) => {
  90. let headers = res.info().headers
  91. console.log(res.text())
  92. report(<Assert key="request should not use chunked encoding"
  93. expect={undefined}
  94. actual={headers['transfer-encoding']}/>)
  95. fs.unlink(path)
  96. done()
  97. })
  98. })