diff --git a/package.json b/package.json index 279e7de..b212e56 100644 --- a/package.json +++ b/package.json @@ -33,20 +33,19 @@ "module-error": "^1.0.1" }, "devDependencies": { - "@types/node": "^20.11.8", - "@voxpelli/tsconfig": "^10.0.0", + "@types/node": "^22.7.7", + "@voxpelli/tsconfig": "^15.0.0", "airtap": "^4.0.4", "airtap-electron": "^1.0.0", "airtap-playwright": "^1.0.1", - "electron": "^28.2.0", - "hallmark": "^4.0.0", + "electron": "^30.5.1", + "hallmark": "^5.0.1", "nyc": "^15.1.0", - "sinon": "^17.0.1", - "standard": "^17.1.0", - "tap-arc": "^1.2.2", - "tape": "^5.7.4", + "standard": "^17.1.2", + "tap-arc": "^1.3.2", + "tape": "^5.9.0", "ts-standard": "^12.0.2", - "typescript": "^5.3.3" + "typescript": "^5.6.3" }, "repository": { "type": "git", diff --git a/test/self.js b/test/self.js index 553a079..e4396c5 100644 --- a/test/self.js +++ b/test/self.js @@ -1,11 +1,10 @@ 'use strict' const test = require('tape') -const sinon = require('sinon') const isBuffer = require('is-buffer') const { Buffer } = require('buffer') const { AbstractLevel, AbstractChainedBatch } = require('..') -const { MinimalLevel } = require('./util') +const { MinimalLevel, createSpy } = require('./util') const getRangeOptions = require('../lib/range-options') const testCommon = require('./common')({ @@ -55,7 +54,7 @@ test('manifest is required', function (t) { }) test('test open() extensibility when new', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const expectedOptions = { createIfMissing: true, errorIfExists: false } const Test = implement(AbstractLevel, { _open: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -81,7 +80,7 @@ test('test open() extensibility when new', async function (t) { test('test open() extensibility when open', function (t) { t.plan(2) - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const Test = implement(AbstractLevel, { _open: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -97,7 +96,7 @@ test('test open() extensibility when open', function (t) { test('test opening explicitly gives a chance to capture an error', async function (t) { t.plan(3) - const spy = sinon.spy(async function (options) { throw new Error('_open error') }) + const spy = createSpy(async function (options) { throw new Error('_open error') }) const Test = implement(AbstractLevel, { _open: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -111,7 +110,7 @@ test('test opening explicitly gives a chance to capture an error', async functio }) test('test constructor options are forwarded to open()', async function (t) { - const spy = sinon.spy(async function (options) { }) + const spy = createSpy(async function (options) { }) const Test = implement(AbstractLevel, { _open: spy }) const test = new Test({ encodings: { utf8: true } }, { passive: true, @@ -132,7 +131,7 @@ test('test constructor options are forwarded to open()', async function (t) { }) test('test close() extensibility when open', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const Test = implement(AbstractLevel, { _close: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -145,7 +144,7 @@ test('test close() extensibility when open', async function (t) { }) test('test close() extensibility when new', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const Test = implement(AbstractLevel, { _close: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -288,7 +287,7 @@ test('open() error is combined with resource error', async function (t) { }) test('test get() extensibility', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const expectedOptions = { keyEncoding: 'utf8', valueEncoding: 'utf8' } const expectedKey = 'a key' const Test = implement(AbstractLevel, { _get: spy }) @@ -314,7 +313,7 @@ test('test get() extensibility', async function (t) { }) test('test getMany() extensibility', async function (t) { - const spy = sinon.spy(async () => ['x']) + const spy = createSpy(async () => ['x']) const expectedOptions = { keyEncoding: 'utf8', valueEncoding: 'utf8' } const expectedKey = 'a key' const Test = implement(AbstractLevel, { _getMany: spy }) @@ -340,7 +339,7 @@ test('test getMany() extensibility', async function (t) { }) test('test del() extensibility', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const expectedOptions = { options: 1, keyEncoding: 'utf8' } const expectedKey = 'a key' const Test = implement(AbstractLevel, { _del: spy }) @@ -365,7 +364,7 @@ test('test del() extensibility', async function (t) { }) test('test put() extensibility', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const expectedOptions = { options: 1, keyEncoding: 'utf8', valueEncoding: 'utf8' } const expectedKey = 'a key' const expectedValue = 'a value' @@ -393,7 +392,7 @@ test('test put() extensibility', async function (t) { }) test('batch([]) extensibility', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const expectedOptions = { options: 1 } const expectedArray = [ { type: 'put', key: '1', value: '1', keyEncoding: 'utf8', valueEncoding: 'utf8' }, @@ -431,7 +430,7 @@ test('batch([]) extensibility', async function (t) { test('batch([]) with empty array is a noop', function (t) { t.plan(1) - const spy = sinon.spy() + const spy = createSpy() const Test = implement(AbstractLevel, { _batch: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -443,7 +442,7 @@ test('batch([]) with empty array is a noop', function (t) { }) test('test chained batch() extensibility', async function (t) { - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const expectedOptions = { options: 1 } const Test = implement(AbstractLevel, { _batch: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -473,7 +472,7 @@ test('test chained batch() extensibility', async function (t) { test('test chained batch() with no operations is a noop', function (t) { t.plan(1) - const spy = sinon.spy(async function () {}) + const spy = createSpy(async function () {}) const Test = implement(AbstractLevel, { _batch: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -485,7 +484,7 @@ test('test chained batch() with no operations is a noop', function (t) { }) test('test chained batch() (custom _chainedBatch) extensibility', async function (t) { - const spy = sinon.spy() + const spy = createSpy() const Test = implement(AbstractLevel, { _chainedBatch: spy }) const test = new Test({ encodings: { utf8: true } }) @@ -583,7 +582,7 @@ test('test AbstractChainedBatch#write() extensibility with options', async funct test('test AbstractChainedBatch#put() extensibility', function (t) { t.plan(8) - const spy = sinon.spy() + const spy = createSpy() const expectedKey = 'key' const expectedValue = 'value' const Test = implement(AbstractChainedBatch, { _put: spy }) @@ -610,7 +609,7 @@ test('test AbstractChainedBatch#put() extensibility', function (t) { test('test AbstractChainedBatch#del() extensibility', function (t) { t.plan(6) - const spy = sinon.spy() + const spy = createSpy() const expectedKey = 'key' const Test = implement(AbstractChainedBatch, { _del: spy }) const db = testCommon.factory() @@ -634,7 +633,7 @@ test('test AbstractChainedBatch#del() extensibility', function (t) { test('test AbstractChainedBatch#clear() extensibility', function (t) { t.plan(4) - const spy = sinon.spy() + const spy = createSpy() const Test = implement(AbstractChainedBatch, { _clear: spy }) const db = testCommon.factory() @@ -652,7 +651,7 @@ test('test AbstractChainedBatch#clear() extensibility', function (t) { test('test clear() extensibility', async function (t) { t.plan((7 * 4) - 3) - const spy = sinon.spy() + const spy = createSpy() const Test = implement(AbstractLevel, { _clear: spy }) const db = new Test({ encodings: { utf8: true } }) @@ -685,7 +684,7 @@ test('test clear() extensibility', async function (t) { test.skip('test serialization extensibility (batch array is not mutated)', function (t) { t.plan(7) - const spy = sinon.spy() + const spy = createSpy() const Test = implement(AbstractLevel, { _batch: spy, _serializeKey: function (key) { diff --git a/test/util.js b/test/util.js index 4495a61..c144a53 100644 --- a/test/util.js +++ b/test/util.js @@ -2,6 +2,7 @@ const { AbstractLevel, AbstractChainedBatch } = require('..') const { AbstractIterator, AbstractKeyIterator, AbstractValueIterator } = require('..') +const noop = function () {} exports.illegalKeys = [ { name: 'null key', key: null }, @@ -53,6 +54,30 @@ exports.nullishEncoding = { } } +// Replacement for sinon package (which breaks too often, on features we don't use) +exports.createSpy = function (fn = noop) { + let calls = [] + + const spy = function (...args) { + const returnValue = fn(...args) + calls.push({ thisValue: this, args, returnValue }) + spy.callCount++ + return returnValue + } + + spy.callCount = 0 + spy.getCall = function (n) { + return calls[n] + } + + spy.resetHistory = function () { + calls = [] + spy.callCount = 0 + } + + return spy +} + const kEntries = Symbol('entries') const kPosition = Symbol('position') const kOptions = Symbol('options')