Skip to content

Commit

Permalink
Increase code coverage to 100% (#20)
Browse files Browse the repository at this point in the history
Category: fix
  • Loading branch information
vweevers authored Jan 26, 2025
1 parent 2c24c62 commit c5abd4a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/breathe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"CHANGELOG.md"
],
"dependencies": {
"abstract-level": "^3.0.0",
"abstract-level": "^3.0.1",
"functional-red-black-tree": "^1.0.1",
"module-error": "^1.0.1"
},
Expand Down
22 changes: 22 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,25 @@ test('throws on unsupported storeEncoding', function (t) {
t.throws(() => new MemoryLevel({ storeEncoding: 'foo' }), (err) => err.code === 'LEVEL_ENCODING_NOT_SUPPORTED')
t.end()
})

test('clear() waits a tick every 500 items', async function (t) {
const db = new MemoryLevel()
const batch = Array(1000)

for (let i = 0; i < batch.length; i++) {
batch[i] = { type: 'put', key: i, value: i }
}

await db.open()
await db.batch(batch)

t.is((await db.keys().all()).length, batch.length)

// This just checks that the code runs OK, not that it waits a
// tick (TODO). Pass in a limit in order to use an iterator
// instead of the fast-path of clear() that just deletes all.
await db.clear({ limit: batch.length * 2 })

t.is((await db.keys().all()).length, 0)
return db.close()
})

0 comments on commit c5abd4a

Please sign in to comment.