설명 없음

test-0.6.3.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import RNFetchBlob from 'react-native-fetch-blob'
  4. import Timer from 'react-timer-mixin'
  5. import {
  6. StyleSheet,
  7. Text,
  8. View,
  9. ScrollView,
  10. CameraRoll,
  11. Platform,
  12. Dimensions,
  13. Image,
  14. } from 'react-native';
  15. const fs = RNFetchBlob.fs
  16. const { Assert, Comparer, Info, prop } = RNTest
  17. const describe = RNTest.config({
  18. group : '0.6.3',
  19. run : true,
  20. expand : true,
  21. timeout : 300000000,
  22. })
  23. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
  24. const dirs = RNFetchBlob.fs.dirs
  25. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  26. false && describe('massive HTTP request', (report, done) => {
  27. return
  28. let promises = []
  29. let progress = []
  30. let begin = Date.now()
  31. for(let i=0; i<1500;i++) {
  32. let p = RNFetchBlob
  33. .config({fileCache : true})
  34. .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
  35. // .progress(function(current, total){
  36. // progress[this] = current/total
  37. // }.bind(i))
  38. promises.push(p)
  39. }
  40. // let it = Timer.setInterval(() => {
  41. // function pgs() {
  42. // let res = []
  43. // for(var i in progress) {
  44. // res.push(<Text key={`download#${i}`}>{`download #${i} ${Math.floor(progress[i]*100)}%`}</Text>)
  45. // }
  46. // return res
  47. // }
  48. // report(<Info key={`progress monitor`} uid="progress">
  49. // {pgs()}
  50. // </Info>)
  51. // }, 1000)
  52. Promise.all(promises).then((resps) => {
  53. for(let i in resps) {
  54. fs.unlink(resps[i].path())
  55. }
  56. report(<Info key={`time = ${(Date.now() - begin) / 1000} sec`}></Info>)
  57. // Timer.clearInterval(it)
  58. done()
  59. })
  60. })
  61. RNTest.config({
  62. group : '0.7.0',
  63. run : true,
  64. expand : false,
  65. timeout : 600000,
  66. })('Upload and download large file', (report, done) => {
  67. let filename = '22mb-dummy-' + Date.now()
  68. let begin = -1
  69. let begin2 = -1
  70. let deb = Date.now()
  71. RNFetchBlob.config({
  72. fileCache : true
  73. })
  74. .fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
  75. .progress((now, total) => {
  76. if(begin === -1)
  77. begin = Date.now()
  78. if(Date.now() - deb < 1000)
  79. return
  80. deb = Date.now()
  81. report(<Info uid="200" key="progress">
  82. <Text>
  83. {`download ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s)`}
  84. </Text>
  85. </Info>)
  86. })
  87. .then((res) => {
  88. try {
  89. deb = Date.now()
  90. // let promise = RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/raw`, {
  91. let promise = RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
  92. Authorization : `Bearer ${DROPBOX_TOKEN}`,
  93. 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
  94. 'Content-Type' : 'application/octet-stream',
  95. }, RNFetchBlob.wrap(res.path()))
  96. promise.uploadProgress((now, total) => {
  97. if(Date.now() - deb < 1000)
  98. return
  99. deb = Date.now()
  100. if(begin2 === -1)
  101. begin2 = Date.now()
  102. let speed = Math.floor(now / (Date.now() - begin2))
  103. report(<Info uid="100" key="progress">
  104. <Text>
  105. {`upload ${now} / ${total} bytes (${speed} kb/s)`}
  106. {` ${Math.floor((total-now)/speed/1000)} seconds left`}
  107. </Text>
  108. </Info>)
  109. })
  110. return promise
  111. } catch(err) { console.log(err) }
  112. })
  113. .then((res) => {
  114. report(<Assert
  115. key="upload should success without crashing app"
  116. expect={filename}
  117. actual={res.json().name}/>)
  118. done()
  119. })
  120. })