Skip to content

Commit

Permalink
add test for reopening writable core
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Sep 10, 2024
1 parent 16d2d26 commit e9b2162
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,51 @@ test('createIfMissing', async function (t) {
await db.close()
})

test('reopen writable core', async function (t) {
const dir = await createTempDir(t)

const core = new Hypercore(dir)
await core.ready()

let appends = 0

t.is(core.length, 0)
t.is(core.writable, true)
t.is(core.readable, true)

core.on('append', function () {
appends++
})

await core.append('hello')
await core.append('world')

const info = await core.info()

t.is(core.length, 2)
t.is(info.byteLength, 10)
t.is(appends, 2)

await core.close()

const core2 = new Hypercore(dir)
await core2.ready()

t.is(core2.length, 2)
t.is(core2.writable, true)
t.is(core2.readable, true)

core2.on('append', function () {
appends++
})

await core2.append('goodbye')
await core2.append('test')

t.is(core2.length, 4)
t.is(appends, 4)
})

test('reopen and overwrite', async function (t) {
const dir = await createTempDir()
let storage = null
Expand Down

0 comments on commit e9b2162

Please sign in to comment.