@libp2p/interop 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,21 +24,20 @@ export function echoStreamTests (factory: DaemonFactory, muxer: Muxer): void {
24
24
 
25
25
  function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
26
26
  describe(`echo streams - ${muxer}`, () => {
27
- let daemons: Daemon[]
27
+ let daemonA: Daemon
28
+ let daemonB: Daemon
28
29
 
29
30
  // Start Daemons
30
31
  before(async function () {
31
32
  this.timeout(20 * 1000)
32
33
 
33
- daemons = await Promise.all([
34
- factory.spawn(optionsA),
35
- factory.spawn(optionsB)
36
- ])
34
+ daemonA = await factory.spawn(optionsA)
35
+ daemonB = await factory.spawn(optionsB)
37
36
 
38
37
  // connect them
39
- const identify0 = await daemons[0].client.identify()
38
+ const identify0 = await daemonA.client.identify()
40
39
 
41
- await daemons[1].client.connect(identify0.peerId, identify0.addrs)
40
+ await daemonB.client.connect(identify0.peerId, identify0.addrs)
42
41
 
43
42
  // jsDaemon1 will take some time to get the peers
44
43
  await new Promise(resolve => setTimeout(resolve, 1000))
@@ -46,21 +45,21 @@ function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: Spa
46
45
 
47
46
  // Stop daemons
48
47
  after(async function () {
49
- if (daemons != null) {
50
- await Promise.all(
51
- daemons.map(async (daemon) => { await daemon.stop() })
52
- )
53
- }
48
+ await Promise.all(
49
+ [daemonA, daemonB]
50
+ .filter(Boolean)
51
+ .map(async d => { await d.stop() })
52
+ )
54
53
  })
55
54
 
56
55
  it(`${optionsA.type} sender to ${optionsB.type} listener`, async function () {
57
56
  this.timeout(10 * 1000)
58
57
 
59
- const receivingIdentity = await daemons[1].client.identify()
58
+ const receivingIdentity = await daemonB.client.identify()
60
59
  const protocol = '/echo/1.0.0'
61
60
  const input = [uint8ArrayFromString('hello world')]
62
61
 
63
- await daemons[1].client.registerStreamHandler(protocol, async (stream) => {
62
+ await daemonB.client.registerStreamHandler(protocol, async (stream) => {
64
63
  await pipe(
65
64
  stream,
66
65
  async function * (source) {
@@ -72,7 +71,7 @@ function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: Spa
72
71
  )
73
72
  })
74
73
 
75
- const stream = await daemons[0].client.openStream(receivingIdentity.peerId, protocol)
74
+ const stream = await daemonA.client.openStream(receivingIdentity.peerId, protocol)
76
75
 
77
76
  // without this the socket can close before we receive a response
78
77
  const responseReceived = defer()