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

Commit

Permalink
Test manifest integration with deferred-leveldown
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Oct 4, 2019
1 parent f564895 commit 1458d79
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/self.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ suite({
encodings: false
})

// Integration tests that can't use a generic testCommon.factory()
require('./self/manifest-test')

if (!process.browser) {
require('./browserify-test')(test)
}
60 changes: 60 additions & 0 deletions test/self/manifest-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict'

var test = require('tape')
var levelup = require('../..')
var memdown = require('memdown')
var sinon = require('sinon')

test('manifest: additionalMethod is proxied', function (t) {
var mem = memdown()

mem.beep = sinon.spy()
mem.supports = { additionalMethods: { beep: true } }

var db = levelup(mem)

t.is(typeof db.beep, 'function')
t.is(typeof levelup.prototype.beep, 'undefined')

db.beep()
t.is(mem.beep.callCount, 0, 'deferred')

db.on('open', function () {
t.is(mem.beep.callCount, 1)
t.same(mem.beep.getCall(0).args, [])

db.beep('boop')
t.same(mem.beep.getCall(1).args, ['boop'])

db.close(t.end.bind(t))
})
})

test('manifest: additionalMethod is proxied even if function does not exist', function (t) {
var mem = memdown()
mem.supports = { additionalMethods: { beep: true } }
var db = levelup(mem)

t.is(typeof db.beep, 'function')
t.is(typeof levelup.prototype.beep, 'undefined')
t.end()
})

test('manifest: approximateSize() et al are proxied even if manifest does not exist', function (t) {
var mem = memdown()

// deferred-leveldown should feature-detect these methods (for now)
mem.approximateSize = function () {}
mem.compactRange = function () {}

mem.otherMethod = function () {}
mem.supports = null

var db = levelup(mem)

t.is(typeof db.approximateSize, 'function')
t.is(typeof db.compactRange, 'function')
t.is(typeof db.otherMethod, 'undefined')

t.end()
})

0 comments on commit 1458d79

Please sign in to comment.