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

Commit f6b7a4f

Browse files
authored
Test manifest integration with deferred-leveldown (#681)
1 parent b83dde8 commit f6b7a4f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

test/self.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ suite({
5252
encodings: false
5353
})
5454

55+
// Integration tests that can't use a generic testCommon.factory()
56+
require('./self/manifest-test')
57+
5558
if (!process.browser) {
5659
require('./browserify-test')(test)
5760
}

test/self/manifest-test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)