33
44const expect = require ( 'chai' ) . expect
55const isNode = require ( 'detect-node' )
6+ const waterfall = require ( 'async/waterfall' )
7+ const path = require ( 'path' )
8+
69const FactoryClient = require ( '../factory/factory-client' )
10+
711describe ( 'ls' , function ( ) {
12+ if ( ! isNode ) {
13+ return
14+ }
15+
816 let ipfs
917 let fc
18+ let folderHash
1019
1120 before ( function ( done ) {
1221 this . timeout ( 20 * 1000 ) // slow CI
1322 fc = new FactoryClient ( )
14- fc . spawnNode ( ( err , node ) => {
15- expect ( err ) . to . not . exist
16- ipfs = node
17- done ( )
18- } )
23+ waterfall ( [
24+ ( cb ) => fc . spawnNode ( cb ) ,
25+ ( node , cb ) => {
26+ ipfs = node
27+ const filesPath = path . join ( __dirname , '../data/test-folder' )
28+ ipfs . util . addFromFs ( filesPath , { recursive : true } , cb )
29+ } ,
30+ ( hashes , cb ) => {
31+ folderHash = hashes [ hashes . length - 1 ] . hash
32+ cb ( )
33+ }
34+ ] , done )
1935 } )
2036
2137 after ( ( done ) => {
2238 fc . dismantle ( done )
2339 } )
2440
2541 it ( 'should correctly retrieve links' , function ( done ) {
26- if ( ! isNode ) {
27- return done ( )
28- }
29-
30- ipfs . ls ( 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' , ( err , res ) => {
42+ ipfs . ls ( folderHash , ( err , res ) => {
3143 expect ( err ) . to . not . exist
3244
3345 expect ( res ) . to . have . a . property ( 'Objects' )
3446 expect ( res . Objects [ 0 ] ) . to . have . a . property ( 'Links' )
35- expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' , 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' )
47+ expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' )
3648 done ( )
3749 } )
3850 } )
@@ -46,8 +58,6 @@ describe('ls', function () {
4658 } )
4759
4860 it ( 'should correctly handle a nonexisting path' , function ( done ) {
49- if ( ! isNode ) return done ( )
50-
5161 ipfs . ls ( 'QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there' , ( err , res ) => {
5262 expect ( err ) . to . exist
5363 expect ( res ) . to . not . exist
@@ -57,13 +67,11 @@ describe('ls', function () {
5767
5868 describe ( 'promise' , ( ) => {
5969 it ( 'should correctly retrieve links' , ( ) => {
60- if ( ! isNode ) return
61-
62- return ipfs . ls ( 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' )
70+ return ipfs . ls ( folderHash )
6371 . then ( ( res ) => {
6472 expect ( res ) . to . have . a . property ( 'Objects' )
6573 expect ( res . Objects [ 0 ] ) . to . have . a . property ( 'Links' )
66- expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' , 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' )
74+ expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' )
6775 } )
6876 } )
6977
@@ -75,8 +83,6 @@ describe('ls', function () {
7583 } )
7684
7785 it ( 'should correctly handle a nonexisting path' , ( ) => {
78- if ( ! isNode ) return
79-
8086 return ipfs . ls ( 'QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there' )
8187 . catch ( ( err ) => {
8288 expect ( err ) . to . exist
0 commit comments