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

Commit 67188ae

Browse files
committed
test updates
1 parent 6462130 commit 67188ae

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

src/files.js

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const path = require('path')
88
const fs = require('fs')
99
const isNode = require('detect-node')
1010
const concat = require('concat-stream')
11+
const through = require('through2')
1112

1213
module.exports = (common) => {
13-
describe.only('.files', () => {
14+
describe('.files', () => {
1415
let smallFile
1516
let bigFile
1617
let ipfs
@@ -313,7 +314,7 @@ module.exports = (common) => {
313314
expect(err).to.not.exist
314315
stream.pipe(concat((files) => {
315316
expect(files).to.be.length(1)
316-
expect(files[0].path).to.deep.equal(mhBuf)
317+
expect(files[0].path).to.deep.equal(hash)
317318
files[0].content.pipe(concat((content) => {
318319
expect(content.toString()).to.contain('Check out some of the other files in this directory:')
319320
done()
@@ -326,13 +327,22 @@ module.exports = (common) => {
326327
const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
327328
ipfs.files.get(hash, (err, stream) => {
328329
expect(err).to.not.exist
329-
stream.pipe(concat((files) => {
330-
expect(files).to.be.length(1)
331-
expect(files[0].path).to.equal(hash)
332-
files[0].content.pipe(concat((content) => {
333-
expect(content).to.deep.equal(bigFile)
334-
done()
330+
331+
// accumulate the files and their content
332+
var files = []
333+
stream.pipe(through.obj((file, enc, next) => {
334+
file.content.pipe(concat((content) => {
335+
files.push({
336+
path: file.path,
337+
content: content
338+
})
339+
next()
335340
}))
341+
}, () => {
342+
expect(files.length).to.equal(1)
343+
expect(files[0].path).to.equal(hash)
344+
expect(files[0].content).to.deep.equal(bigFile)
345+
done()
336346
}))
337347
})
338348
})
@@ -341,21 +351,35 @@ module.exports = (common) => {
341351
const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
342352
ipfs.files.get(hash, (err, stream) => {
343353
expect(err).to.not.exist
344-
stream.pipe(concat((files) => {
345-
expect(files).to.be.length(8)
354+
355+
// accumulate the files and their content
356+
var files = []
357+
stream.pipe(through.obj((file, enc, next) => {
358+
file.content.pipe(concat((content) => {
359+
files.push({
360+
path: file.path,
361+
content: content
362+
})
363+
next()
364+
}))
365+
}, () => {
366+
expect(files).to.be.length(10)
346367
var paths = files.map((file) => {
347368
return file.path
348369
})
349370
expect(paths).to.deep.equal([
371+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP',
350372
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
351373
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
374+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
375+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty',
376+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt',
377+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt',
352378
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
353379
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
354380
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
355-
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty',
356-
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt',
357-
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt'
358381
])
382+
done()
359383
}))
360384
})
361385
})

0 commit comments

Comments
 (0)