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 6c213d7
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,53 @@ 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)

await core2.close()
})

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

0 comments on commit 6c213d7

Please sign in to comment.