Skip to content

Increase code coverage to 100% #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
Loading