暫無描述

test-0.9.5.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. TouchableOpacity,
  13. } from 'react-native';
  14. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  15. window.Blob = RNFetchBlob.polyfill.Blob
  16. const fs = RNFetchBlob.fs
  17. const { Assert, Comparer, Info, prop } = RNTest
  18. const describe = RNTest.config({
  19. group : '0.9.5',
  20. run : true,
  21. expand : false,
  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. // describe('issue #122 force response data format', (report, done) => {
  28. //
  29. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`, {
  30. // 'RNFB-Response' : 'base64'
  31. // })
  32. // .then((res) => {
  33. // let r = RNFetchBlob.base64.decode(res.data)
  34. // report(
  35. // <Assert key="test data verify" expect="fetchblob-dev" actual={JSON.parse(r).name}/>,
  36. // <Assert key="should successfully decode the data" expect={true} actual={true}/>)
  37. // return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`)
  38. // })
  39. // .then((res) => {
  40. // report(
  41. // <Assert key="response should in format of plain-text" expect="fetchblob-dev" actual={JSON.parse(res.data).name}/>)
  42. // done()
  43. // })
  44. // .catch(() => {
  45. // report(
  46. // <Assert key="Should successfully decode the data" expect={true} actual={false}/>)
  47. // done()
  48. // })
  49. //
  50. // })
  51. describe('#129 memory leaking when enable uploadProgress', (report, done) => {
  52. let file = null
  53. let count = 0
  54. RNFetchBlob.config({ fileCache : true })
  55. .fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
  56. .then((res) => {
  57. file = res.path()
  58. for(let i=0;i<10;i++){
  59. RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload`, {
  60. 'Transfer-Encoding' : 'Chunked'
  61. }, RNFetchBlob.wrap(file))
  62. .uploadProgress((current, total) => {})
  63. .then(() => {
  64. count ++
  65. if(count >= 10) {
  66. fs.unlink(file)
  67. done()
  68. }
  69. })
  70. }
  71. })
  72. })
  73. false && describe('#131 status code != 200 should not throw an error', (report, done) => {
  74. let count = 0
  75. let codes = [404, 500, 501, 403]
  76. codes.forEach((code) => {
  77. RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/xhr-code/${code}`, {
  78. 'Cache-Control' : 'no-store'
  79. })
  80. .then(function(res) {
  81. report(<Assert key={`status code should be ${this}`} expect={Math.floor(this)} actual={Math.floor(res.info().status)}/>)
  82. count ++
  83. if(count >= 4)
  84. done()
  85. }.bind(code))
  86. .catch(function(err) {
  87. report(<Assert key={`status code ${this} should not cause error`} expect={true} actual={false}/>)
  88. count++
  89. }.bind(code))
  90. })
  91. })