From d34c0638c7a50234bd72e6520a78444f181801e6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 12 Feb 2020 11:02:36 +0100 Subject: [PATCH] chore: address review --- package.json | 4 +++- test/stream-to-ma-conn.spec.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8e3f37a..d0ec543 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,9 @@ "chai": "^4.2.0", "dirty-chai": "^2.0.1", "it-pair": "^1.0.0", - "multiaddr": "^7.3.0" + "it-pipe": "^1.1.0", + "multiaddr": "^7.3.0", + "streaming-iterables": "^4.1.2" }, "dependencies": { "abortable-iterator": "^3.0.0", diff --git a/test/stream-to-ma-conn.spec.js b/test/stream-to-ma-conn.spec.js index df5b250..9e223b5 100644 --- a/test/stream-to-ma-conn.spec.js +++ b/test/stream-to-ma-conn.spec.js @@ -7,6 +7,8 @@ const expect = chai.expect chai.use(dirtyChai) const pair = require('it-pair') +const pipe = require('it-pipe') +const { collect } = require('streaming-iterables') const multiaddr = require('multiaddr') const streamToMaConn = require('../src/stream-to-ma-conn') @@ -35,4 +37,20 @@ describe('Convert stream into a multiaddr connection', () => { maConn.close() expect(maConn.timeline.close).to.exist() }) + + it('can stream data over the multiaddr connection', async () => { + const stream = pair() + const maConn = streamToMaConn({ stream }) + + const data = 'hey' + const streamData = await pipe( + [data], + maConn, + collect + ) + + expect(streamData).to.eql([data]) + // underlying stream end closes the connection + expect(maConn.timeline.close).to.exist() + }) })