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

Commit 4c53976

Browse files
committed
test updates
1 parent 80c2827 commit 4c53976

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
@@ -310,7 +311,7 @@ module.exports = (common) => {
310311
expect(err).to.not.exist
311312
stream.pipe(concat((files) => {
312313
expect(files).to.be.length(1)
313-
expect(files[0].path).to.deep.equal(mhBuf)
314+
expect(files[0].path).to.deep.equal(hash)
314315
files[0].content.pipe(concat((content) => {
315316
expect(content.toString()).to.contain('Check out some of the other files in this directory:')
316317
done()
@@ -323,13 +324,22 @@ module.exports = (common) => {
323324
const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
324325
ipfs.files.get(hash, (err, stream) => {
325326
expect(err).to.not.exist
326-
stream.pipe(concat((files) => {
327-
expect(files).to.be.length(1)
328-
expect(files[0].path).to.equal(hash)
329-
files[0].content.pipe(concat((content) => {
330-
expect(content).to.deep.equal(bigFile)
331-
done()
327+
328+
// accumulate the files and their content
329+
var files = []
330+
stream.pipe(through.obj((file, enc, next) => {
331+
file.content.pipe(concat((content) => {
332+
files.push({
333+
path: file.path,
334+
content: content
335+
})
336+
next()
332337
}))
338+
}, () => {
339+
expect(files.length).to.equal(1)
340+
expect(files[0].path).to.equal(hash)
341+
expect(files[0].content).to.deep.equal(bigFile)
342+
done()
333343
}))
334344
})
335345
})
@@ -338,21 +348,35 @@ module.exports = (common) => {
338348
const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
339349
ipfs.files.get(hash, (err, stream) => {
340350
expect(err).to.not.exist
341-
stream.pipe(concat((files) => {
342-
expect(files).to.be.length(8)
351+
352+
// accumulate the files and their content
353+
var files = []
354+
stream.pipe(through.obj((file, enc, next) => {
355+
file.content.pipe(concat((content) => {
356+
files.push({
357+
path: file.path,
358+
content: content
359+
})
360+
next()
361+
}))
362+
}, () => {
363+
expect(files).to.be.length(10)
343364
var paths = files.map((file) => {
344365
return file.path
345366
})
346367
expect(paths).to.deep.equal([
368+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP',
347369
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
348370
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
371+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
372+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty',
373+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt',
374+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt',
349375
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
350376
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
351377
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
352-
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty',
353-
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt',
354-
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt'
355378
])
379+
done()
356380
}))
357381
})
358382
})

0 commit comments

Comments
 (0)