diff --git a/package.json b/package.json index a07d257..25d93b1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/basic.js b/test/basic.js index 1365ddc..52d482d 100644 --- a/test/basic.js +++ b/test/basic.js @@ -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) @@ -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() + } +}) diff --git a/test/helpers/index.js b/test/helpers/index.js index a0479d9..9e622f9 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -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