|
@@ -31,46 +31,26 @@ const dirs = RNFetchBlob.fs.dirs
|
31
|
31
|
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
|
32
|
32
|
let begin = Date.now()
|
33
|
33
|
|
34
|
|
-describe('#177 multipart upload event only triggers once', (report, done) => {
|
|
34
|
+describe("Invalid promise.resolve call after task is canceled #176", (report, done) => {
|
|
35
|
+
|
|
36
|
+ let task = RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
|
|
37
|
+
|
|
38
|
+ task
|
|
39
|
+ .then(() => {
|
|
40
|
+ report(<Assert key="Promise should not resolved" expect={true} actual={false}/>);
|
|
41
|
+ })
|
|
42
|
+
|
|
43
|
+ .catch(() => {
|
|
44
|
+ report(<Assert key="Promise should not resolved" expect={true} actual={true}/>);
|
|
45
|
+ done()
|
|
46
|
+ });
|
|
47
|
+
|
|
48
|
+ task.progress((current, total) => {
|
|
49
|
+ report(<Info key={`${Math.floor(current/1024)}kb of ${Math.floor(total/1024)}kb`} uid="report"/>)
|
|
50
|
+ })
|
|
51
|
+
|
|
52
|
+ setTimeout(() => {
|
|
53
|
+ task.cancel();
|
|
54
|
+ }, 2000)
|
35
|
55
|
|
36
|
|
- try{
|
37
|
|
- let localFile = null
|
38
|
|
- let filename = 'dummy-'+Date.now()
|
39
|
|
- RNFetchBlob.config({
|
40
|
|
- fileCache : true
|
41
|
|
- })
|
42
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
|
43
|
|
- .then((res) => {
|
44
|
|
- localFile = res.path()
|
45
|
|
- return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
|
46
|
|
- 'Content-Type' : 'multipart/form-data',
|
47
|
|
- }, [
|
48
|
|
- { name : 'test-img', filename : filename, data: 'RNFetchBlob-file://' + localFile},
|
49
|
|
- { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
|
50
|
|
- { name : 'field1', data : 'hello !!'},
|
51
|
|
- { name : 'field2', data : 'hello2 !!'}
|
52
|
|
- ])
|
53
|
|
- .uploadProgress({ interval : 100 },(now, total) => {
|
54
|
|
- console.log(now/total)
|
55
|
|
- })
|
56
|
|
- })
|
57
|
|
- .then((resp) => {
|
58
|
|
- resp = resp.json()
|
59
|
|
- report(
|
60
|
|
- <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
|
61
|
|
- <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
|
62
|
|
- )
|
63
|
|
- return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
|
64
|
|
- })
|
65
|
|
- .then((resp) => {
|
66
|
|
- report(<Info key="uploaded image">
|
67
|
|
- <Image
|
68
|
|
- style={styles.image}
|
69
|
|
- source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
|
70
|
|
- </Info>)
|
71
|
|
- done()
|
72
|
|
- })
|
73
|
|
- } catch(err) {
|
74
|
|
- console.log(err)
|
75
|
|
- }
|
76
|
56
|
})
|