forked from libp2p/js-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-2.js
33 lines (25 loc) · 779 Bytes
/
test-2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import path from 'path'
import { fileURLToPath } from 'url'
import { execa } from 'execa'
import pWaitFor from 'p-wait-for'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
export async function test () {
let discoveredNodes = 0
process.stdout.write('2.js\n')
const proc = execa('node', [path.join(__dirname, '2.js')], {
cwd: path.resolve(__dirname),
all: true
})
proc.all.on('data', async (data) => {
process.stdout.write(data)
const str = uint8ArrayToString(data)
str.split('\n').forEach(line => {
if (line.includes('Discovered:')) {
discoveredNodes++
}
})
})
await pWaitFor(() => discoveredNodes > 1, 600000)
proc.kill()
}