Updates
This commit is contained in:
@@ -1,26 +1,39 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PPearRuntimeSession, PROTOCOL } = require('../index.js')
|
||||
const { HyperPearRuntimeSession, PROTOCOL } = require('../index.js')
|
||||
|
||||
test('exports', (t) => {
|
||||
t.ok(HyperP2PPearRuntimeSession)
|
||||
t.ok(PROTOCOL)
|
||||
t.ok(HyperPearRuntimeSession)
|
||||
t.is(PROTOCOL, 'pear-runtime-session/v1')
|
||||
})
|
||||
|
||||
test('basic operation', async (t) => {
|
||||
const m = new HyperP2PPearRuntimeSession()
|
||||
m.put('k', 1); t.is(m.get('k'), 1)
|
||||
test('startSession activeSessions', async (t) => {
|
||||
const m = new HyperPearRuntimeSession()
|
||||
const s = m.startSession({ app: 'demo' })
|
||||
t.is(m.activeSessions().length, 1)
|
||||
t.is(m.activeSessions()[0].id, s.id)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('validation', async (t) => {
|
||||
const m = new HyperP2PPearRuntimeSession()
|
||||
try { m.put(null, 1) } catch (e) { t.ok(e) }
|
||||
test('endSession removes from active', async (t) => {
|
||||
const m = new HyperPearRuntimeSession()
|
||||
const s = m.startSession({})
|
||||
m.endSession(s.id)
|
||||
t.is(m.activeSessions().length, 0)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('endSession twice throws', async (t) => {
|
||||
const m = new HyperPearRuntimeSession()
|
||||
const s = m.startSession({})
|
||||
m.endSession(s.id)
|
||||
try { m.endSession(s.id) } catch (e) { t.ok(e) }
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('getStats', async (t) => {
|
||||
const m = new HyperP2PPearRuntimeSession()
|
||||
t.ok(m.getStats().protocol)
|
||||
const m = new HyperPearRuntimeSession()
|
||||
m.startSession({})
|
||||
t.is(m.getStats().started, 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user