From 662b5fdabc848d78bae6e7ec581927f0fab72c5e Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 31 Oct 2019 14:45:54 +0100 Subject: [PATCH] fix: dont mutate select protocols (#55) --- src/select.js | 2 +- test/dialer.spec.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/select.js b/src/select.js index 7d13114..59af498 100644 --- a/src/select.js +++ b/src/select.js @@ -6,7 +6,7 @@ const multistream = require('./multistream') const handshake = require('it-handshake') module.exports = async (stream, protocols, protocolId) => { - protocols = Array.isArray(protocols) ? protocols : [protocols] + protocols = Array.isArray(protocols) ? [...protocols] : [protocols] const { reader, writer, rest, stream: shakeStream } = handshake(stream) const protocol = protocols.shift() diff --git a/test/dialer.spec.js b/test/dialer.spec.js index 43e114b..a559ae7 100644 --- a/test/dialer.spec.js +++ b/test/dialer.spec.js @@ -83,6 +83,7 @@ describe('Dialer', () => { const mss = new MSS.Dialer(duplex) const selection = await mss.select(protocols) + expect(protocols).to.have.length(2) expect(selection.protocol).to.equal(selectedProtocol) // Ensure stream is usable after selection