import RNTest from './react-native-testkit/' import React from 'react' import RNFetchBlob from 'react-native-fetch-blob' import { StyleSheet, Text, View, ScrollView, Platform, Dimensions, Image, } from 'react-native'; window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest window.Blob = RNFetchBlob.polyfill.Blob window.fetch = new RNFetchBlob.polyfill.Fetch({ auto : true, binaryContentTypes : ['image/', 'video/', 'audio/'] }).build() const fs = RNFetchBlob.fs const { Assert, Comparer, Info, prop } = RNTest const describe = RNTest.config({ group : '0.9.0', run : true, expand : false, timeout : 20000, }) const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop() const dirs = RNFetchBlob.fs.dirs let prefix = ((Platform.OS === 'android') ? 'file://' : '') describe('cache control header and range request test', (report, done) => { let image = RNTest.prop('image') let part = [ `${fs.dirs.DocumentDir}/cache-control-test-part1.png`, `${fs.dirs.DocumentDir}/cache-control-test-part2.png`, `${fs.dirs.DocumentDir}/cache-control-test-part3.png` ] let tmp = null RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', { Authorization : `Bearer ${DROPBOX_TOKEN}`, 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}', 'Content-Type' : 'application/octet-stream', }, image) .then((resp) => { resp = resp.json() report( ) return RNFetchBlob.config({ path : part[0], }) .fetch('GET', 'https://content.dropboxapi.com/1/files/auto/rn-upload/' + FILENAME, { Authorization : `Bearer ${DROPBOX_TOKEN}`, 'Cache-Control' : 'no-store', 'Range' : 'bytes=0-23000' }) }) .then((res) => { let size = Math.floor(res.info().headers['Content-Length']) report() return RNFetchBlob.config({ path : part[2] }) .fetch('GET', 'https://content.dropboxapi.com/1/files/auto/rn-upload/' + FILENAME, { Authorization : `Bearer ${DROPBOX_TOKEN}`, 'Range' : 'bytes=23001-23975', 'Cache-Control' : 'no-store' }) }) .then((res) => { let size = Math.floor(res.info().headers['Content-Length']) report() return fs.appendFile(part[0], part[2], 'uri') }) .then((written) => { return fs.stat(part[0]) }) .then((stat) => { report() done() }) }) describe('#73 unicode response BASE64 content test', (report, done) => { fetch(`${TEST_SERVER_URL}/unicode`, { method : 'GET' }) .then((res) => { return res.json() }) .then((data) => { report() done() }) }) describe('#73 unicode response content test', (report, done) => { let expect = '中文!檔案\\u00測試 ABCDE 測試' RNFetchBlob.config({ fileCache : true }) .fetch('GET', `${TEST_SERVER_URL}/public/utf8-dummy`, { method : 'GET' }) .then((res) => res.readFile('utf8')) .then((data) => { report( ) done() }) }) describe = RNTest.config({ group : '0.9.0', run : true, expand : true, timeout : 24000 }) describe('request should not retry after timed out', (report, done) => { let count = 0 let task = RNFetchBlob .fetch('GET', `${TEST_SERVER_URL}/timeout408/${Date.now()}`) task.then((res) => { report() }) .catch(() => { task.cancel() count ++ }) setTimeout(() => { report() done() }, 12000) }) describe = RNTest.config({ group : '0.9.0', run : true, expand : true, timeout : 65000 }) describe('long live download or upload task won\'t timeout', (report, done) => { RNFetchBlob.config({timeout : 0}) .fetch('GET', `${TEST_SERVER_URL}/long/`) .then((res) => { report( , ) done() }) })