@@ -80,20 +80,19 @@ describe('ls', function () {
80
80
81
81
methods . forEach ( method => {
82
82
describe ( `ls ${ method . name } ` , function ( ) {
83
- it ( 'lists the root directory by default' , ( ) => {
83
+ it ( 'lists the root directory by default' , async ( ) => {
84
84
const fileName = `small-file-${ Math . random ( ) } .txt`
85
85
const content = Buffer . from ( 'Hello world' )
86
-
87
- return mfs . write ( `/${ fileName } ` , content , {
86
+
87
+ await mfs . write ( `/${ fileName } ` , content , {
88
88
create : true
89
89
} )
90
- . then ( ( ) => method . ls ( ) )
91
- . then ( ( result ) => method . collect ( result ) )
92
- . then ( files => {
93
- expect ( files . find ( file => file . name === fileName ) ) . to . be . ok ( )
94
- } )
90
+ const result = await method . ls ( )
91
+ const files = await method . collect ( result )
92
+
93
+ expect ( files . find ( file => file . name === fileName ) ) . to . be . ok ( )
95
94
} )
96
-
95
+
97
96
it ( 'refuses to lists files with an empty path' , ( ) => {
98
97
return method . ls ( '' )
99
98
. then ( ( result ) => method . collect ( result ) )
@@ -104,7 +103,7 @@ describe('ls', function () {
104
103
expect ( error . message ) . to . contain ( 'paths must not be empty' )
105
104
} )
106
105
} )
107
-
106
+
108
107
it ( 'refuses to lists files with an invalid path' , ( ) => {
109
108
return method . ls ( 'not-valid' )
110
109
. then ( ( result ) => method . collect ( result ) )
@@ -115,12 +114,12 @@ describe('ls', function () {
115
114
expect ( error . message ) . to . contain ( 'paths must start with a leading /' )
116
115
} )
117
116
} )
118
-
117
+
119
118
it ( 'lists files in a directory' , ( ) => {
120
119
const dirName = `dir-${ Math . random ( ) } `
121
120
const fileName = `small-file-${ Math . random ( ) } .txt`
122
121
const content = Buffer . from ( 'Hello world' )
123
-
122
+
124
123
return mfs . write ( `/${ dirName } /${ fileName } ` , content , {
125
124
create : true ,
126
125
parents : true
@@ -135,12 +134,12 @@ describe('ls', function () {
135
134
expect ( files [ 0 ] . hash ) . to . equal ( '' )
136
135
} )
137
136
} )
138
-
137
+
139
138
it ( 'lists files in a directory with meta data' , ( ) => {
140
139
const dirName = `dir-${ Math . random ( ) } `
141
140
const fileName = `small-file-${ Math . random ( ) } .txt`
142
141
const content = Buffer . from ( 'Hello world' )
143
-
142
+
144
143
return mfs . write ( `/${ dirName } /${ fileName } ` , content , {
145
144
create : true ,
146
145
parents : true
@@ -156,11 +155,11 @@ describe('ls', function () {
156
155
expect ( files [ 0 ] . size ) . to . equal ( content . length )
157
156
} )
158
157
} )
159
-
158
+
160
159
it ( 'lists a file' , ( ) => {
161
160
const fileName = `small-file-${ Math . random ( ) } .txt`
162
161
const content = Buffer . from ( 'Hello world' )
163
-
162
+
164
163
return mfs . write ( `/${ fileName } ` , content , {
165
164
create : true
166
165
} )
@@ -174,11 +173,11 @@ describe('ls', function () {
174
173
expect ( files [ 0 ] . hash ) . to . equal ( '' )
175
174
} )
176
175
} )
177
-
176
+
178
177
it ( 'lists a file with meta data' , ( ) => {
179
178
const fileName = `small-file-${ Math . random ( ) } .txt`
180
179
const content = Buffer . from ( 'Hello world' )
181
-
180
+
182
181
return mfs . write ( `/${ fileName } ` , content , {
183
182
create : true
184
183
} )
@@ -193,11 +192,11 @@ describe('ls', function () {
193
192
expect ( files [ 0 ] . size ) . to . equal ( content . length )
194
193
} )
195
194
} )
196
-
195
+
197
196
it ( 'lists a file with a base32 hash' , ( ) => {
198
197
const fileName = `small-file-${ Math . random ( ) } .txt`
199
198
const content = Buffer . from ( 'Hello world' )
200
-
199
+
201
200
return mfs . write ( `/${ fileName } ` , content , {
202
201
create : true
203
202
} )
@@ -214,7 +213,7 @@ describe('ls', function () {
214
213
expect ( files [ 0 ] . hash . startsWith ( 'b' ) ) . to . equal ( true )
215
214
} )
216
215
} )
217
-
216
+
218
217
it ( 'fails to list non-existent file' , ( ) => {
219
218
return method . ls ( '/i-do-not-exist' )
220
219
. then ( ( result ) => method . collect ( result ) )
@@ -225,53 +224,53 @@ describe('ls', function () {
225
224
expect ( error . message ) . to . contain ( 'does not exist' )
226
225
} )
227
226
} )
228
-
227
+
229
228
it ( 'lists a sharded directory contents' , async ( ) => {
230
229
const shardSplitThreshold = 10
231
230
const fileCount = 11
232
231
const dirPath = await createShardedDirectory ( mfs , shardSplitThreshold , fileCount )
233
-
232
+
234
233
const files = await method . collect ( await method . ls ( dirPath , {
235
234
long : true
236
235
} ) )
237
-
236
+
238
237
expect ( files . length ) . to . equal ( fileCount )
239
-
238
+
240
239
files . forEach ( file => {
241
240
// should be a file
242
241
expect ( file . type ) . to . equal ( 0 )
243
242
} )
244
243
} )
245
-
244
+
246
245
it ( 'lists a file inside a sharded directory directly' , async ( ) => {
247
246
const dirPath = await createShardedDirectory ( mfs )
248
-
249
- const files = await method . collect ( await method . ls ( dirPath , {
247
+
248
+ const files = await method . collect ( await method . ls ( dirPath , {
250
249
long : true
251
250
} ) )
252
-
251
+
253
252
const filePath = `${ dirPath } /${ files [ 0 ] . name } `
254
-
253
+
255
254
// should be able to ls new file directly
256
255
expect ( await method . collect ( await method . ls ( filePath , {
257
256
long : true
258
257
} ) ) ) . to . not . be . empty ( )
259
258
} )
260
-
259
+
261
260
it ( 'lists the contents of a directory inside a sharded directory' , async ( ) => {
262
261
const shardedDirPath = await createShardedDirectory ( mfs )
263
262
const dirPath = `${ shardedDirPath } /subdir-${ Math . random ( ) } `
264
263
const fileName = `small-file-${ Math . random ( ) } .txt`
265
-
264
+
266
265
await mfs . mkdir ( `${ dirPath } ` )
267
266
await mfs . write ( `${ dirPath } /${ fileName } ` , Buffer . from ( [ 0 , 1 , 2 , 3 ] ) , {
268
267
create : true
269
268
} )
270
-
269
+
271
270
const files = await method . collect ( await method . ls ( dirPath , {
272
271
long : true
273
272
} ) )
274
-
273
+
275
274
expect ( files . length ) . to . equal ( 1 )
276
275
expect ( files . filter ( file => file . name === fileName ) ) . to . be . ok ( )
277
276
} )
0 commit comments