Skip to content

Commit

Permalink
Test reopen (#12)
Browse files Browse the repository at this point in the history
* test reopen

* fix standard

* force bump hyperbee
  • Loading branch information
mafintosh authored Oct 18, 2024
1 parent 1e5ea7f commit b78af43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"compact-encoding": "^2.15.0",
"generate-object-property": "^2.0.0",
"generate-string": "^1.0.1",
"hyperbee": "^2.20.1",
"hyperbee": "^2.20.4",
"hyperschema": "^1.0.0",
"index-encoder": "^3.2.0",
"rocksdb-native": "^2.3.1",
Expand Down
18 changes: 18 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const definition = require('./fixtures/definition')
const { test } = require('./helpers')
const tmp = require('test-tmp')

test('basic full example', async function ({ create }, t) {
const db = await create(definition)
Expand Down Expand Up @@ -243,3 +244,20 @@ test('watch', async function ({ create }, t) {

await db.close()
})

test('basic reopen', async function ({ create }, t) {
const storage = await tmp(t)
{
const db = await create(definition, { storage })
await db.insert('members', { id: 'maf', age: 34 })
await db.flush()
await db.close()
}

{
const db = await create(definition, { storage })
const all = await db.find('members').toArray()
t.is(all.length, 1)
await db.close()
}
})
4 changes: 2 additions & 2 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function createTester (type) {
}

function creator (t, createHyperDB) {
return async function fromDefinition (def, opts) {
return async function fromDefinition (def, opts = {}) {
if (!HyperDB.isDefinition(def)) {
return fromDefinition(require(`../fixtures/generated/${(def && def.fixture) || 1}/hyperdb`), def)
}

const db = createHyperDB(await tmp(t), def, opts)
const db = createHyperDB(opts.storage || await tmp(t), def, opts)
const engine = db.engine

// just to help catch leaks
Expand Down

0 comments on commit b78af43

Please sign in to comment.