説明なし

test-0.10.3.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import _ from 'lodash'
  4. import RNFetchBlob from 'react-native-fetch-blob'
  5. import {
  6. StyleSheet,
  7. Text,
  8. View,
  9. ScrollView,
  10. Linking,
  11. Platform,
  12. Dimensions,
  13. BackAndroid,
  14. AsyncStorage,
  15. Image,
  16. } from 'react-native';
  17. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  18. window.Blob = RNFetchBlob.polyfill.Blob
  19. const JSONStream = RNFetchBlob.JSONStream
  20. const fs = RNFetchBlob.fs
  21. const { Assert, Comparer, Info, prop } = RNTest
  22. const describe = RNTest.config({
  23. group : '0.10.3',
  24. run : true,
  25. expand : true,
  26. timeout : 20000,
  27. })
  28. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  29. const dirs = RNFetchBlob.fs.dirs
  30. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  31. let begin = Date.now()
  32. //
  33. // describe('#230 #249 cookies manipulation', (report, done) => {
  34. //
  35. // RNFetchBlob
  36. // .fetch('GET', `${TEST_SERVER_URL}/cookie/249230`)
  37. // .then((res) => RNFetchBlob.net.getCookies())
  38. // .then((cookies) => {
  39. // console.log(cookies)
  40. // report(<Assert
  41. // key="should set 10 cookies"
  42. // expect={10}
  43. // actual={cookies['localhost'].length}/>)
  44. // return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
  45. // })
  46. // .then((res) => {
  47. // console.log(res.data)
  48. // let cookies = String(res.data).split(';')
  49. // report(<Assert
  50. // key="should send 10 cookies"
  51. // expect={10}
  52. // actual={cookies.length}/>)
  53. // return RNFetchBlob.net.removeCookies()
  54. // })
  55. // .then(() => RNFetchBlob.net.getCookies('localhost'))
  56. // .then((cookies) => {
  57. // report(<Assert
  58. // key="should have no cookies"
  59. // expect={undefined}
  60. // actual={cookies['localhost']}/>)
  61. // return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
  62. // })
  63. // .then((res) => {
  64. // console.log(res.data)
  65. // let cookies = String(res.data).split(';')
  66. // cookies = _.reject(cookies, r => r.length < 2)
  67. // report(<Assert
  68. // key="should send no cookies"
  69. // expect={0}
  70. // actual={cookies.length}/>)
  71. // done()
  72. // })
  73. //
  74. // })
  75. //
  76. // describe('#254 IOS fs.stat lastModified date correction', (report, done) => {
  77. //
  78. // let path = dirs.DocumentDir + '/temp' + Date.now()
  79. // fs.createFile(path, 'hello', 'utf8' )
  80. // .then(() => fs.stat(path))
  81. // .then((stat) => {
  82. // console.log(stat)
  83. // let p = stat.lastModified / Date.now()
  84. // report(<Assert key="date is correct" expect={true} actual={ p< 1.05 && p > 0.95}/>)
  85. // done()
  86. // })
  87. //
  88. // })
  89. describe('#263 parallel request', (report, done) => {
  90. let urls = [
  91. `${TEST_SERVER_URL}/public/1mb-dummy`,
  92. `${TEST_SERVER_URL}/public/2mb-dummy`,
  93. `${TEST_SERVER_URL}/public/404`
  94. ]
  95. let size = [1000000, 1310720, 23]
  96. let asserts = []
  97. new Promise
  98. .all(urls.map((url) => RNFetchBlob.fetch('GET', url)))
  99. .then((results) => {
  100. _.each(results, (r, i) => {
  101. report(
  102. <Assert key={`redirect URL ${i} should be correct`}
  103. expect={urls[i]}
  104. actual={r.info().redirects[0]}/>)
  105. report(<Assert key={`content ${i} should be correct`}
  106. expect={size[i]}
  107. actual={r.data.length}/>)
  108. })
  109. done()
  110. })
  111. })