Skip to content

Commit

Permalink
Use reachdown package (Level/community#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Sep 14, 2019
1 parent 98b58cb commit 8350402
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"jsondown": "^1.0.0",
"level-community": "^3.0.0",
"nyc": "^14.0.0",
"reachdown": "^1.0.0",
"standard": "^14.0.0",
"tape": "^4.8.0"
},
Expand Down
24 changes: 6 additions & 18 deletions test/suite.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
'use strict'

var test = require('tape')

function isLooseAbstract (db) {
if (!db || typeof db !== 'object') { return false }
return typeof db._batch === 'function' && typeof db._iterator === 'function'
}

function down (db, type) {
if (typeof db.down === 'function') return db.down(type)
if (type && db.type === type) return db
if (isLooseAbstract(db.db)) return down(db.db, type)
if (isLooseAbstract(db._db)) return down(db._db, type)
return type ? null : db
}
var reachdown = require('reachdown')

exports.args = function (level, expectedDown) {
test('without arguments', function (t) {
Expand All @@ -22,7 +10,7 @@ exports.args = function (level, expectedDown) {
var db = level()

db.on('open', function () {
t.ok(down(db) instanceof expectedDown, 'got expected down')
t.ok(reachdown(db) instanceof expectedDown, 'got expected down')
})

db.put('foo', 'bar', function (err) {
Expand All @@ -37,7 +25,7 @@ exports.args = function (level, expectedDown) {
level({ valueEncoding: 'json' }, function (err, db) {
t.ifError(err)
t.ok(db.isOpen())
t.ok(down(db) instanceof expectedDown, 'got expected down')
t.ok(reachdown(db) instanceof expectedDown, 'got expected down')

var key = '' + Math.random()
var value = { test_key: '' + new Date() }
Expand All @@ -61,7 +49,7 @@ exports.args = function (level, expectedDown) {
var value = { test_key: '' + new Date() }

db.on('open', function () {
t.ok(down(db) instanceof expectedDown, 'got expected down')
t.ok(reachdown(db) instanceof expectedDown, 'got expected down')
})

db.put(key, value, function (err) {
Expand All @@ -80,7 +68,7 @@ exports.args = function (level, expectedDown) {
level(function (err, db) {
t.ifError(err)
t.ok(db.isOpen())
t.ok(down(db) instanceof expectedDown, 'got expected down')
t.ok(reachdown(db) instanceof expectedDown, 'got expected down')

db.put('key', 'value', function (err) {
t.notOk(err)
Expand All @@ -101,7 +89,7 @@ exports.customLayers = function (level, expectedDown, expectedUp, rawValue) {
var ret = level(function (err, db) {
t.ifError(err)
t.is(db, ret, 'got db')
t.ok(down(db) instanceof expectedDown, 'got expected down')
t.ok(reachdown(db) instanceof expectedDown, 'got expected down')
t.ok(db instanceof expectedUp, 'got expected up')

db.put('key', 'value', function (err) {
Expand Down

0 comments on commit 8350402

Please sign in to comment.