Increase code coverage to 100% (#20) · Level/memory-level@c5abd4a

3 files changed

lines changed

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
Original file line numberDiff line numberDiff line change

@@ -20,7 +20,7 @@

2020

"CHANGELOG.md"

2121

],

2222

"dependencies": {

23-

"abstract-level": "^3.0.0",

23+

"abstract-level": "^3.0.1",

2424

"functional-red-black-tree": "^1.0.1",

2525

"module-error": "^1.0.1"

2626

},

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+

})