This commit is contained in:
Raven Scott
2026-05-20 22:28:59 -04:00
parent 341542f41b
commit e4400872c0
82 changed files with 2533 additions and 775 deletions
@@ -2,25 +2,34 @@ require('bare-process/global')
const test = require('brittle')
const { HyperP2PStreamTee, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PStreamTee)
t.ok(PROTOCOL)
})
test('exports', (t) => { t.ok(HyperP2PStreamTee); t.is(PROTOCOL, 'stream-tee/v1') })
test('basic operation', async (t) => {
test('tee to branches', async (t) => {
const m = new HyperP2PStreamTee()
m.write('hi'); t.ok(m.read())
m.addBranch('a')
m.addBranch('b')
m.write(require('b4a').from('z'))
t.ok(m.readBranch('a'))
t.ok(m.readBranch('b'))
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PStreamTee()
try { m.write(null) } catch (e) { t.ok(e) }
try { m.addBranch('') } catch (e) { t.ok(e) }
await m.close()
})
test('remove branch', async (t) => {
const m = new HyperP2PStreamTee()
const off = m.addBranch('x')
off()
t.is(m.pending('x'), 0)
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PStreamTee()
t.ok(m.getStats().protocol)
t.is(m.getStats().protocol, 'stream-tee/v1')
await m.close()
})