No Description

test-0.9.0.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. window.fetch = new RNFetchBlob.polyfill.Fetch({
  16. auto : true,
  17. binaryContentTypes : ['image/', 'video/', 'audio/']
  18. }).build()
  19. const fs = RNFetchBlob.fs
  20. const { Assert, Comparer, Info, prop } = RNTest
  21. const describe = RNTest.config({
  22. group : '0.9.0',
  23. run : true,
  24. expand : true,
  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. describe('#73 unicode response BASE64 content test', (report, done) => {
  31. fetch(`${TEST_SERVER_URL}/unicode`, {
  32. method : 'GET'
  33. })
  34. .then((res) => {
  35. return res.json()
  36. })
  37. .then((data) => {
  38. report(<Assert key="data should correct" expect={'你好!'} actual={data.data}/>)
  39. done()
  40. })
  41. })
  42. describe('#73 unicode response content test', (report, done) => {
  43. let expect = '中文!檔案\\u00測試 ABCDE 測試'
  44. RNFetchBlob.config({ fileCache : true })
  45. .fetch('GET', `${TEST_SERVER_URL}/public/utf8-dummy`, {
  46. method : 'GET'
  47. })
  48. .then((res) => res.readFile('utf8'))
  49. .then((data) => {
  50. report(
  51. <Assert key="data should correct"
  52. expect={expect}
  53. actual={data}/>)
  54. done()
  55. })
  56. })
  57. describe = RNTest.config({
  58. group : '0.9.0',
  59. run : true,
  60. expand : true,
  61. timeout : 24000
  62. })
  63. describe('request should not retry after timed out', (report, done) => {
  64. let count = 0
  65. let task = RNFetchBlob
  66. .fetch('GET', `${TEST_SERVER_URL}/timeout408/${Date.now()}`)
  67. task.then((res) => {
  68. report(<Assert key="request should not success" expect={true} actual={false}/>)
  69. })
  70. .catch(() => {
  71. task.cancel()
  72. count ++
  73. })
  74. setTimeout(() => {
  75. report(<Assert key="request does not retry" expect={1} actual={count}/>)
  76. done()
  77. }, 12000)
  78. })
  79. describe = RNTest.config({
  80. group : '0.9.0',
  81. run : true,
  82. expand : true,
  83. timeout : 65000
  84. })
  85. describe('long live download or upload task won\'t timeout', (report, done) => {
  86. RNFetchBlob.config({timeout : 0})
  87. .fetch('GET', `${TEST_SERVER_URL}/long/`)
  88. .then((res) => {
  89. report(
  90. <Assert key="download not terminated" expect={true} actual={true}/>,
  91. <Info key={res.text()}/>)
  92. done()
  93. })
  94. })