|
| 1 | +'use strict' |
| 2 | + |
| 3 | +var test = require('tape') |
| 4 | +var levelup = require('../..') |
| 5 | +var memdown = require('memdown') |
| 6 | +var sinon = require('sinon') |
| 7 | + |
| 8 | +test('manifest: additionalMethod is proxied', function (t) { |
| 9 | + var mem = memdown() |
| 10 | + |
| 11 | + mem.beep = sinon.spy() |
| 12 | + mem.supports = { additionalMethods: { beep: true } } |
| 13 | + |
| 14 | + var db = levelup(mem) |
| 15 | + |
| 16 | + t.is(typeof db.beep, 'function') |
| 17 | + t.is(typeof levelup.prototype.beep, 'undefined') |
| 18 | + |
| 19 | + db.beep() |
| 20 | + t.is(mem.beep.callCount, 0, 'deferred') |
| 21 | + |
| 22 | + db.on('open', function () { |
| 23 | + t.is(mem.beep.callCount, 1) |
| 24 | + t.same(mem.beep.getCall(0).args, []) |
| 25 | + |
| 26 | + db.beep('boop') |
| 27 | + t.same(mem.beep.getCall(1).args, ['boop']) |
| 28 | + |
| 29 | + db.close(t.end.bind(t)) |
| 30 | + }) |
| 31 | +}) |
| 32 | + |
| 33 | +test('manifest: additionalMethod is proxied even if function does not exist', function (t) { |
| 34 | + var mem = memdown() |
| 35 | + mem.supports = { additionalMethods: { beep: true } } |
| 36 | + var db = levelup(mem) |
| 37 | + |
| 38 | + t.is(typeof db.beep, 'function') |
| 39 | + t.is(typeof levelup.prototype.beep, 'undefined') |
| 40 | + t.end() |
| 41 | +}) |
| 42 | + |
| 43 | +test('manifest: approximateSize() et al are proxied even if manifest does not exist', function (t) { |
| 44 | + var mem = memdown() |
| 45 | + |
| 46 | + // deferred-leveldown should feature-detect these methods (for now) |
| 47 | + mem.approximateSize = function () {} |
| 48 | + mem.compactRange = function () {} |
| 49 | + |
| 50 | + mem.otherMethod = function () {} |
| 51 | + mem.supports = null |
| 52 | + |
| 53 | + var db = levelup(mem) |
| 54 | + |
| 55 | + t.is(typeof db.approximateSize, 'function') |
| 56 | + t.is(typeof db.compactRange, 'function') |
| 57 | + t.is(typeof db.otherMethod, 'undefined') |
| 58 | + |
| 59 | + t.end() |
| 60 | +}) |
0 commit comments