This commit is contained in:
Raven Scott
2026-05-20 23:57:33 -04:00
parent ac60c93151
commit 226fca591d
86 changed files with 200 additions and 162 deletions
@@ -0,0 +1,40 @@
require('bare-process/global')
const test = require('brittle')
const { HyperP2PVoidChannel, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PVoidChannel)
t.is(PROTOCOL, 'void-channel/v1')
})
test('publishVoid delivers to subscriber', async (t) => {
const m = new HyperP2PVoidChannel()
let got = null
m.subscribeVoid('empty', (msg) => { got = msg })
m.publishVoid('empty', { reason: 'gone' })
t.is(got.meta.reason, 'gone')
t.ok(got.voided)
await m.close()
})
test('late subscribe gets retained void', async (t) => {
const m = new HyperP2PVoidChannel()
m.publishVoid('ch', { n: 1 })
let got = null
m.subscribeVoid('ch', (msg) => { got = msg })
t.is(got.meta.n, 1)
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PVoidChannel()
try { m.subscribeVoid('x', 'not-fn') } catch (e) { t.ok(e) }
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PVoidChannel()
m.publishVoid('a', {})
t.is(m.getStats().published, 1)
await m.close()
})