Ingen beskrivning

test-0.10.0.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. Linking,
  10. Platform,
  11. Dimensions,
  12. AsyncStorage,
  13. Image,
  14. } from 'react-native';
  15. const JSONStream = RNFetchBlob.JSONStream
  16. const fs = RNFetchBlob.fs
  17. const { Assert, Comparer, Info, prop } = RNTest
  18. const describe = RNTest.config({
  19. group : '0.10.0',
  20. run : true,
  21. expand : true,
  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. let begin = Date.now()
  28. describe('json stream via HTTP', (report, done) => {
  29. let count = 0
  30. JSONStream(`${TEST_SERVER_URL}/public/json-dummy.json`).node('name', (name) => {
  31. count++
  32. if(Date.now() - begin < 100)
  33. return
  34. begin = Date.now()
  35. report(<Info key="report" uid="100">
  36. <Text>{count} records</Text>
  37. </Info>)
  38. done()
  39. })
  40. })
  41. describe('json stream via fs', (report, done) => {
  42. let fetch2 = new RNFetchBlob.polyfill.Fetch({
  43. auto : true
  44. })
  45. let res = null
  46. let count = 0
  47. RNFetchBlob.config({
  48. fileCache : true
  49. })
  50. .fetch('GET',`${TEST_SERVER_URL}/public/json-dummy.json`)
  51. .then((resp) => {
  52. res = resp
  53. JSONStream({
  54. url : RNFetchBlob.wrap(res.path()),
  55. headers : { bufferSize : 10240 }
  56. }).node('name', (name) => {
  57. count++
  58. if(Date.now() - begin < 100)
  59. return
  60. begin = Date.now()
  61. report(<Info key="report" uid="100">
  62. <Text>{count} records</Text>
  63. </Info>)
  64. done()
  65. })
  66. })
  67. })
  68. describe('issue #102', (report, done) => {
  69. let tmp = null
  70. RNFetchBlob.config({ fileCache: true, appendExt : 'png' })
  71. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  72. .then((res) => {
  73. tmp = res
  74. RNFetchBlob.ios.previewDocument(res.path())
  75. return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {},
  76. [{ name : String(1), data : RNFetchBlob.wrap(res.path()), filename: '#102-test-image.png' }])
  77. })
  78. .then((res) => tmp.flush())
  79. .then(() => {
  80. done()
  81. })
  82. })