Ei kuvausta

test-0.10.1.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. BackAndroid,
  13. AsyncStorage,
  14. Image,
  15. } from 'react-native';
  16. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  17. window.Blob = RNFetchBlob.polyfill.Blob
  18. const JSONStream = RNFetchBlob.JSONStream
  19. const fs = RNFetchBlob.fs
  20. const { Assert, Comparer, Info, prop } = RNTest
  21. const describe = RNTest.config({
  22. group : '0.10.1',
  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. let begin = Date.now()
  31. describe("Invalid promise.resolve call after task is canceled #176", (report, done) => {
  32. let task = RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
  33. task
  34. .then(() => {
  35. report(<Assert key="Promise should not resolved" expect={true} actual={false}/>);
  36. })
  37. .catch(() => {
  38. report(<Assert key="Promise should not resolved" expect={true} actual={true}/>);
  39. done()
  40. });
  41. task.progress((current, total) => {
  42. report(<Info key={`${Math.floor(current/1024)}kb of ${Math.floor(total/1024)}kb`} uid="report"/>)
  43. })
  44. setTimeout(() => {
  45. task.cancel();
  46. }, 2000)
  47. })
  48. describe('passing empty value to fs.lstat doest not crash the app #205', (report, done) => {
  49. let path = fs.dirs.DocumentDir +'/testfile' + Date.now()
  50. fs.createFile(path, path, 'utf8')
  51. .then(() => fs.lstat(null))
  52. .catch(() => {
  53. done()
  54. })
  55. })
  56. describe('media scanner test #203', (report, done) => {
  57. RNFetchBlob
  58. .config({ path : fs.dirs.DownloadDir +'/#203-'+Date.now()+'.png' , appendExt : 'png' })
  59. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  60. .then((res) => {
  61. console.log(res.path())
  62. fs.scanFile([ { path : res.path() } ])
  63. })
  64. .then(() => {
  65. done()
  66. })
  67. })