Parcourir la source

#8 Change test code

Ben Hsieh il y a 8 ans
Parent
révision
38905e6e45
4 fichiers modifiés avec 95 ajouts et 112 suppressions
  1. 8
    8
      test/test-0.5.x.js
  2. 31
    31
      test/test-android.js
  3. 52
    70
      test/test-fs.js
  4. 4
    3
      test/test-init.js

+ 8
- 8
test/test-0.5.x.js Voir le fichier

87
 })
87
 })
88
 
88
 
89
 let localFile = null
89
 let localFile = null
90
-let sysDirs = null
90
+let sysDirs = RNFetchBlob.fs.dirs
91
+let dirs = RNFetchBlob.fs.dirs
91
 
92
 
92
 describe('Upload from file storage', (report, done) => {
93
 describe('Upload from file storage', (report, done) => {
93
   let filename = ''
94
   let filename = ''
94
   let filepath = ''
95
   let filepath = ''
95
-  fs.getSystemDirs().then((dirs) => {
96
-    sysDirs = dirs
97
-    filename = Platform.OS + '0.5.0-' + Date.now() + '-from-storage.png'
98
-    filepath = dirs.DocumentDir + '/' + filename
99
-    return RNFetchBlob.config({ path : filepath })
100
-                      .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
101
-  })
96
+
97
+  filename = Platform.OS + '0.5.0-' + Date.now() + '-from-storage.png'
98
+  filepath = dirs.DocumentDir + '/' + filename
99
+  RNFetchBlob
100
+  .config({ path : filepath })
101
+  .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
102
   .then((resp) => {
102
   .then((resp) => {
103
       let path = resp.path()
103
       let path = resp.path()
104
       localFile = path
104
       localFile = path

+ 31
- 31
test/test-android.js Voir le fichier

17
 const describe = RNTest.config({
17
 const describe = RNTest.config({
18
   group : 'Android only functions',
18
   group : 'Android only functions',
19
   run : Platform.OS === 'android',
19
   run : Platform.OS === 'android',
20
-  expand : false,
20
+  expand : true,
21
 })
21
 })
22
 const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
22
 const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
23
 
23
 
26
 // Android only tests
26
 // Android only tests
27
 
27
 
28
 let tmpFilePath = null
28
 let tmpFilePath = null
29
+const dirs = RNFetchBlob.fs.dirs
29
 
30
 
30
 describe('Download with notification', (report, done) => {
31
 describe('Download with notification', (report, done) => {
31
   let filePath = null
32
   let filePath = null
32
   let filename = `test-${Date.now()}.png`
33
   let filename = `test-${Date.now()}.png`
33
-  RNFetchBlob.fs.getSystemDirs().then((dirs) => {
34
-    filePath = `${dirs.DownloadDir}/${filename}`
35
-    return RNFetchBlob.config({
36
-        path : filePath,
37
-        addAndroidDownloads : {
38
-          title : 'RNFetchBlob test download success',
39
-          description : `File description added by RNFetchblob`,
40
-          mediaScannable : true,
41
-          mime : "image/png",
42
-          notification : true
43
-        }
44
-      })
45
-      .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
34
+
35
+  filePath = `${dirs.DownloadDir}/${filename}`
36
+  RNFetchBlob.config({
37
+    path : filePath,
38
+    addAndroidDownloads : {
39
+      title : 'RNFetchBlob test download success',
40
+      description : `File description added by RNFetchblob`,
41
+      mediaScannable : true,
42
+      mime : "image/png",
43
+      notification : true
44
+    }
46
   })
45
   })
46
+  .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
47
   .then((resp) => {
47
   .then((resp) => {
48
     tmpFilePath = resp.path()
48
     tmpFilePath = resp.path()
49
     report(<Info key={`image from ${tmpFilePath}`}>
49
     report(<Info key={`image from ${tmpFilePath}`}>
57
 })
57
 })
58
 
58
 
59
 describe('MediaScanner tests ', (report, done) => {
59
 describe('MediaScanner tests ', (report, done) => {
60
-  let filePath = null
61
   let filename = `scannable-test-${Date.now()}.png`
60
   let filename = `scannable-test-${Date.now()}.png`
62
-  let dirs = null
63
-  RNFetchBlob.fs.getSystemDirs().then((resp) => {
64
-    dirs = resp
65
-    filePath = `${dirs.DownloadDir}/${filename}`
66
-    return RNFetchBlob.config({
67
-        path : filePath,
68
-      })
69
-      .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
61
+  let filePath = `${dirs.DownloadDir}/${filename}`
62
+  RNFetchBlob.config({
63
+    path : filePath,
70
   })
64
   })
65
+  .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
71
   .then((resp) => {
66
   .then((resp) => {
72
     tmpFilePath = resp.path()
67
     tmpFilePath = resp.path()
73
     return RNFetchBlob.fs.scanFile([
68
     return RNFetchBlob.fs.scanFile([
74
       { path:resp.path() }
69
       { path:resp.path() }
75
     ])
70
     ])
76
-    .then(() => {
77
-      report(<Assert key="scan success" expect={true} actual={true}/>)
78
-      return RNFetchBlob
79
-              .config({
80
-                path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
81
-              })
82
-              .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
83
-    })
71
+  })
72
+  .then(() => {
73
+    report(<Assert key="scan success" expect={true} actual={true}/>)
74
+    console.log(dirs)
75
+    for(let i in dirs) {
76
+      console.log(i)
77
+    }
78
+    console.log(dirs.DCIMDir)
79
+    return RNFetchBlob
80
+            .config({
81
+              path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
82
+            })
83
+            .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
84
   })
84
   })
85
   .then((resp) => {
85
   .then((resp) => {
86
     fs.scanFile([{
86
     fs.scanFile([{

+ 52
- 70
test/test-fs.js Voir le fichier

19
 })
19
 })
20
 
20
 
21
 let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
21
 let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
22
-let dirs = null
22
+let dirs = RNFetchBlob.fs.dirs
23
 
23
 
24
 describe('Get storage folders', (report, done) => {
24
 describe('Get storage folders', (report, done) => {
25
-  fs.getSystemDirs().then((resp) => {
26
-    dirs = resp
27
-    console.log(dirs)
28
-    report(
29
-      <Assert key="system folders should exists" expect={resp} comparer={Comparer.exists} />,
30
-      <Assert key="check properties"
31
-        expect={['DocumentDir', 'CacheDir']}
32
-        comparer={Comparer.hasProperties}
33
-        actual={dirs}
34
-      />,
35
-      <Info key="System Folders">
36
-        <Text>{`${JSON.stringify(dirs)}`}</Text>
37
-      </Info>
38
-    )
39
-    done()
40
-  })
41
-
25
+  report(
26
+    <Assert key="system folders should exists" expect={resp} comparer={Comparer.exists} />,
27
+    <Assert key="check properties"
28
+      expect={['DocumentDir', 'CacheDir']}
29
+      comparer={Comparer.hasProperties}
30
+      actual={dirs}
31
+    />,
32
+    <Info key="System Folders">
33
+      <Text>{`${JSON.stringify(dirs)}`}</Text>
34
+    </Info>
35
+  )
36
+  done()
42
 })
37
 })
43
 
38
 
44
 describe('ls API test', (report, done) => {
39
 describe('ls API test', (report, done) => {
286
 })
281
 })
287
 
282
 
288
 describe('ASCII data test', (report, done) => {
283
 describe('ASCII data test', (report, done) => {
289
-  let p = null
284
+  let p = dirs.DocumentDir + '/ASCII-test-' + Date.now()
290
   let expect = 'fetch-blob-'+Date.now()
285
   let expect = 'fetch-blob-'+Date.now()
291
-  fs.getSystemDirs()
292
-    .then((dirs) => {
293
-      p = dirs.DocumentDir + '/ASCII-test-' + Date.now()
294
-      return fs.createFile(p, 'utf8')
295
-    })
286
+
287
+  fs.createFile(p, 'utf8')
296
     .then(() => {
288
     .then(() => {
297
       return fs.writeStream(p, 'ascii', false)
289
       return fs.writeStream(p, 'ascii', false)
298
     })
290
     })
326
 })
318
 })
327
 
319
 
328
 describe('ASCII file test', (report, done) => {
320
 describe('ASCII file test', (report, done) => {
329
-  let p = ''
321
+  let p = dirs.DocumentDir + '/'
330
   let filename = ''
322
   let filename = ''
331
   let expect = []
323
   let expect = []
332
   let base64 = RNFetchBlob.base64
324
   let base64 = RNFetchBlob.base64
333
-  fs.getSystemDirs().then((dirs) => {
334
-    p = dirs.DocumentDir + '/'
335
-    filename = 'ASCII-file-test' + Date.now() + '.txt'
336
-    expect = 'ascii test ' + Date.now()
337
-    return fs.createFile(p + filename, getASCIIArray(expect), 'ascii')
338
-  })
339
-  .then(() => {
340
-    fs.readStream(p + filename, 'base64').then((rs) => {
341
-      let actual = ''
342
-      rs.open()
343
-      rs.onData((chunk) => {
344
-        actual += chunk
345
-      })
346
-      rs.onEnd(() => {
347
-        report(<Assert key="written data verify"
348
-          expect={expect}
349
-          actual={base64.decode(actual)}/>)
350
-        done()
325
+  filename = 'ASCII-file-test' + Date.now() + '.txt'
326
+  expect = 'ascii test ' + Date.now()
327
+  fs.createFile(p + filename, getASCIIArray(expect), 'ascii')
328
+    .then(() => {
329
+      fs.readStream(p + filename, 'base64').then((rs) => {
330
+        let actual = ''
331
+        rs.open()
332
+        rs.onData((chunk) => {
333
+          actual += chunk
334
+        })
335
+        rs.onEnd(() => {
336
+          report(<Assert key="written data verify"
337
+            expect={expect}
338
+            actual={base64.decode(actual)}/>)
339
+          done()
340
+        })
351
       })
341
       })
352
     })
342
     })
353
-  })
354
 })
343
 })
355
 
344
 
356
 describe('format conversion', (report, done) => {
345
 describe('format conversion', (report, done) => {
357
-  let p = ''
358
-  fs.getSystemDirs().then((dirs) => {
359
-    p = dirs.DocumentDir + '/foo-' + Date.now()
360
-    return fs.createFile(p, [102, 111, 111], 'ascii')
361
-  })
362
-  .then(() => {
363
-    fs.readStream(p, 'utf8').then((stream) => {
364
-      let res = []
365
-      stream.open()
366
-      stream.onData((chunk) => {
367
-        res+=chunk
368
-      })
369
-      stream.onEnd(() => {
370
-        report(
371
-          <Assert key="write utf8 and read by ascii"
372
-            expect="foo"
373
-            actual={res}/>)
374
-            done()
346
+  let p = dirs.DocumentDir + '/foo-' + Date.now()
347
+  fs.createFile(p, [102, 111, 111], 'ascii')
348
+    .then(() => {
349
+      fs.readStream(p, 'utf8').then((stream) => {
350
+        let res = []
351
+        stream.open()
352
+        stream.onData((chunk) => {
353
+          res+=chunk
354
+        })
355
+        stream.onEnd(() => {
356
+          report(
357
+            <Assert key="write utf8 and read by ascii"
358
+              expect="foo"
359
+              actual={res}/>)
360
+              done()
361
+        })
375
       })
362
       })
376
     })
363
     })
377
-  })
378
 })
364
 })
379
 
365
 
380
 describe('stat and lstat test', (report, done) => {
366
 describe('stat and lstat test', (report, done) => {
381
-  let p = ''
382
-  let dirs = null
367
+  let p = dirs.DocumentDir + '/' + 'ls-stat-test' + Date.now()
383
   let file = null
368
   let file = null
384
-  fs.getSystemDirs().then((resp) => {
385
-    dirs = resp
386
-    p = dirs.DocumentDir + '/' + 'ls-stat-test' + Date.now()
387
-    return fs.lstat(dirs.DocumentDir)
388
-  })
369
+
370
+  fs.lstat(dirs.DocumentDir)
389
   // stat a folder
371
   // stat a folder
390
   .then((stat) => {
372
   .then((stat) => {
391
     report(
373
     report(

+ 4
- 3
test/test-init.js Voir le fichier

51
     })
51
     })
52
 })
52
 })
53
 
53
 
54
-require('./test-fs')
55
-require('./test-0.1.x-0.4.x')
56
-require('./test-0.5.x')
54
+
55
+// require('./test-fs')
56
+// require('./test-0.1.x-0.4.x')
57
+// require('./test-0.5.x')
57
 require('./test-android')
58
 require('./test-android')