Skip to content

Commit 32ea510

Browse files
committed
Increase code coverage to 100%
Category: none
1 parent f17515f commit 32ea510

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/breathe.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
// Use setImmediate() in Node.js to allow IO in between work
4+
/* istanbul ignore else: coverage currently does not include browsers */
45
if (typeof process !== 'undefined' && !process.browser && typeof global !== 'undefined' && typeof global.setImmediate === 'function') {
56
const setImmediate = global.setImmediate
67

test.js

+22
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,25 @@ test('throws on unsupported storeEncoding', function (t) {
3838
t.throws(() => new MemoryLevel({ storeEncoding: 'foo' }), (err) => err.code === 'LEVEL_ENCODING_NOT_SUPPORTED')
3939
t.end()
4040
})
41+
42+
test('clear() waits a tick every 500 items', async function (t) {
43+
const db = new MemoryLevel()
44+
const batch = Array(1000)
45+
46+
for (let i = 0; i < batch.length; i++) {
47+
batch[i] = { type: 'put', key: i, value: i }
48+
}
49+
50+
await db.open()
51+
await db.batch(batch)
52+
53+
t.is((await db.keys().all()).length, batch.length)
54+
55+
// This just checks that the code runs OK, not that it waits a
56+
// tick (TODO). Pass in a limit in order to use an iterator
57+
// instead of the fast-path of clear() that just deletes all.
58+
await db.clear({ limit: batch.length * 2 })
59+
60+
t.is((await db.keys().all()).length, 0)
61+
return db.close()
62+
})

0 commit comments

Comments
 (0)