Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 8be5ead

Browse files
authored
Restore support of empty prefix option (#185)
This restores a previous behavior (of `level-js` < 3) that unknown to us, was provided by the since-removed IDBWrapper. Backport of #184.
1 parent 556b0c6 commit 8be5ead

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Level (location, opts) {
2323
}
2424

2525
this.location = location
26-
this.prefix = opts.prefix || DEFAULT_PREFIX
26+
this.prefix = opts.prefix == null ? DEFAULT_PREFIX : opts.prefix
2727
this.version = parseInt(opts.version || 1, 10)
2828
}
2929

test/custom-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ module.exports = function (leveljs, test, testCommon) {
4747
})
4848
})
4949

50+
test('empty prefix', function (t) {
51+
var db = testCommon.factory({ prefix: '' })
52+
53+
t.ok(db.location, 'instance has location property')
54+
t.is(db.prefix, '', 'instance has prefix property')
55+
56+
db.open(function (err) {
57+
t.notOk(err, 'no open error')
58+
59+
var idb = db.db
60+
var databaseName = idb.name
61+
var storeNames = idb.objectStoreNames
62+
63+
t.is(databaseName, db.location, 'database name is prefixed')
64+
t.is(storeNames.length, 1, 'created 1 object store')
65+
t.is(storeNames.item(0), db.location, 'object store name equals location')
66+
67+
db.close(t.end.bind(t))
68+
})
69+
})
70+
5071
test('put Buffer value, get Buffer value', function (t) {
5172
var level = testCommon.factory()
5273
level.open(function (err) {

test/structured-clone-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ var types = [
128128

129129
// Types that are not supported by the structured clone algorithm
130130
var illegalTypes = [
131-
{ name: 'Error', value: new Error() },
131+
// Latest Chrome does seem to support Error, so skip this test.
132+
// { name: 'Error', value: new Error() },
133+
132134
{ name: 'Function', value: function () {} },
133135
{ name: 'DOMNode', value: global.document }
134136
]

0 commit comments

Comments
 (0)