Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 981018e

Browse files
committed
#8 add test cases for stat and lstat
1 parent c0cde03 commit 981018e

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

src/fs.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ function mkdir(path:string):Promise {
163163
* @return {RNFetchBlobFile}
164164
*/
165165
function stat(path:string):Promise<RNFetchBlobFile> {
166-
166+
return new Promise((resolve, reject) => {
167+
RNFetchBlob.stat(path, (err, stat) => {
168+
if(err)
169+
reject(err)
170+
else
171+
resolve(stat)
172+
})
173+
})
167174
}
168175

169176
/**
@@ -175,7 +182,14 @@ function stat(path:string):Promise<RNFetchBlobFile> {
175182
* @return {Promise}
176183
*/
177184
function scanFile(paths:Array<string>, mimes: Array<string>):Promise {
178-
185+
return new Promise((resolve, reject) => {
186+
RNFetchBlob.scanFile(path, (err) => {
187+
if(err)
188+
reject(err)
189+
else
190+
resolve()
191+
})
192+
})
179193
}
180194

181195
function cp(path:string, dest:string):Promise<boolean> {
@@ -201,7 +215,14 @@ function mv(path:string, dest:string):Promise<boolean> {
201215
}
202216

203217
function lstat(path:string):Promise<Array<RNFetchBlobFile>> {
204-
218+
return new Promise((resolve, reject) => {
219+
RNFetchBlob.lstat(path, (err, stat) => {
220+
if(err)
221+
reject(err)
222+
else
223+
resolve(stat)
224+
})
225+
})
205226
}
206227

207228
function ls(path:string):Promise<Array<String>> {

test/react-native-testkit/lib/comparer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ export default {
1818
isArray : (a, b) => Array.isArray(a),
1919
hasProperties : (a, b) => {
2020
let res = true
21+
let c = 0
2122
for(let i in a) {
2223
let found = false
2324
for(let j in b) {
24-
if(b[j] === i) {
25+
c++
26+
if(j === a[i]) {
2527
found = true
2628
break;
2729
}

test/test-fs.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ let dirs = null
2424
describe('Get storage folders', (report, done) => {
2525
fs.getSystemDirs().then((resp) => {
2626
dirs = resp
27+
console.log(dirs)
2728
report(
2829
<Assert key="system folders should exists" expect={resp} comparer={Comparer.exists} />,
2930
<Assert key="check properties"
30-
expect={resp}
31+
expect={['DocumentDir', 'CacheDir']}
3132
comparer={Comparer.hasProperties}
32-
actual={['DocumentDir', 'CacheDir', 'DCIMDir', 'DownloadDir']}
33+
actual={dirs}
3334
/>,
3435
<Info key="System Folders">
3536
<Text>{`${JSON.stringify(dirs)}`}</Text>
@@ -376,6 +377,36 @@ describe('format conversion', (report, done) => {
376377
})
377378
})
378379

380+
describe('stat and lstat test', (report, done) => {
381+
let p = ''
382+
let dirs = null
383+
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+
})
389+
// stat a folder
390+
.then((stat) => {
391+
report(
392+
<Assert key="result should be an array"
393+
expect={true}
394+
actual={Array.isArray(stat)}/>)
395+
file = stat[0].path
396+
return fs.stat(file)
397+
})
398+
.then((stat) => {
399+
console.log(stat)
400+
report(
401+
<Assert key="should have properties"
402+
expect={['size', 'type', 'lastModified', 'filename', 'path']}
403+
comparer={Comparer.hasProperties}
404+
actual={stat}/>)
405+
done()
406+
})
407+
408+
})
409+
379410
function getASCIIArray(str) {
380411
let r = []
381412
for(let i=0;i<str.length;i++) {

0 commit comments

Comments
 (0)