Skip to content

Commit 5488bcb

Browse files
committedOct 11, 2019
test: Add to get.js test coverage
- Add an extra test for adding new listener once the stream has already been created, which covers this specific untested scenario - Added usage of the `size` option which was also untested - Brings test coverage for the `get.js` file to 100%
1 parent c40323f commit 5488bcb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
 

‎test/get.js

+32
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,38 @@ test('basic stream get', (t) => {
403403
})
404404
})
405405

406+
test('get.stream add new listeners post stream creation', (t) => {
407+
const fixture = new Tacks(
408+
CacheContent({
409+
[INTEGRITY]: CONTENT
410+
})
411+
)
412+
fixture.create(CACHE)
413+
414+
t.plan(3)
415+
return index.insert(CACHE, KEY, INTEGRITY, opts()).then(() => {
416+
const OPTS = { memoize: false, size: CONTENT.length }
417+
const stream = get.stream(CACHE, KEY, OPTS)
418+
419+
// Awaits index.find in order to synthetically retrieve a point in runtime
420+
// in which the stream has already been created and has the entry data
421+
// available, allowing for the validation of the newListener event handler
422+
return index.find(CACHE, KEY)
423+
.then(() => {
424+
[
425+
'integrity',
426+
'metadata',
427+
'size'
428+
].forEach(ev => {
429+
stream.on(ev, () => {
430+
t.ok(`${ev} listener added`)
431+
})
432+
})
433+
return stream.concat()
434+
})
435+
})
436+
})
437+
406438
test('get.copy will throw ENOENT if not found', (t) => {
407439
const DEST = path.join(CACHE, 'not-found')
408440
return get.copy(CACHE, 'NOT-FOUND', DEST)

0 commit comments

Comments
 (0)
Please sign in to comment.