Skip to content

Commit

Permalink
Increase code coverage to 100%
Browse files Browse the repository at this point in the history
Category: none
  • Loading branch information
vweevers committed Jan 26, 2025
1 parent f17515f commit 32ea510
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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
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 32ea510

Please sign in to comment.