설명 없음

test-0.8.2.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.8.2',
  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. console.log(data)
  39. report(<Assert key="data should correct" expect={'你好!'} actual={data.data}/>)
  40. done()
  41. })
  42. })
  43. describe('#73 unicode response content test', (report, done) => {
  44. let expect = '中文!檔案\\u00測試 ABCDE 測試'
  45. RNFetchBlob.config({ fileCache : true })
  46. .fetch('GET', `${TEST_SERVER_URL}/public/utf8-dummy`, {
  47. method : 'GET'
  48. })
  49. .then((res) => res.readFile('utf8'))
  50. .then((data) => {
  51. report(
  52. <Assert key="data should correct"
  53. expect={expect}
  54. actual={data}/>)
  55. done()
  56. })
  57. })
  58. RNTest.config({
  59. group : '0.8.2',
  60. run : true,
  61. expand : true,
  62. timeout : 24000
  63. })('request should not retry after timed out', (report, done) => {
  64. let count = 0
  65. RNFetchBlob
  66. // .config({timeout : 2000})
  67. .fetch('GET', `${TEST_SERVER_URL}/timeout408`)
  68. .then((res) => {
  69. report(<Assert key="request should not success" expect={true} actual={false}/>)
  70. })
  71. .catch(() => {
  72. count ++
  73. })
  74. setTimeout(() => {
  75. report(<Assert key="request does not retry" expect={1} actual={count}/>)
  76. done()
  77. }, 8000)
  78. })