Нет описания

test-0.9.6.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.6',
  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('support #141 breakpoint download', (report, done) => {
  28. let dest = dirs.DocumentDir + '/breakpoint.png'
  29. let firstChunkSize = 0
  30. fs.unlink(dest)
  31. .then(() => {
  32. let session = RNFetchBlob.config({
  33. path : dest
  34. })
  35. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
  36. 'Cache-Control' : 'no-cache',
  37. Range : 'bytes=0-200'
  38. })
  39. .then((res) => {
  40. console.log(res.info())
  41. console.log(res.data)
  42. return fs.stat(res.path())
  43. })
  44. .then((stat) => {
  45. firstChunkSize = Math.floor(stat.size)
  46. console.log(firstChunkSize)
  47. })
  48. .then(() => {
  49. RNFetchBlob.config({
  50. path : dest + '?append=true'
  51. })
  52. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
  53. 'Cache-Control' : 'no-cache',
  54. Range : 'bytes=201-'
  55. })
  56. .then((res) => {
  57. console.log(res.info())
  58. console.log(res.path())
  59. return fs.stat(res.path())
  60. })
  61. .then((stat) => {
  62. report(
  63. <Info key="image">
  64. <Image style={RNTest.prop('styles').image} source={{uri : prefix + dest}}/>
  65. </Info>,
  66. <Assert key="request data should append to existing one" expect={23975} actual={Math.floor(stat.size)}/>)
  67. done()
  68. })
  69. })
  70. })
  71. })
  72. describe('support download/upload progress interval and division #140 ', (report, done) => {
  73. })