Skip to content

Commit

Permalink
Bump dev dependencies and remove sinon
Browse files Browse the repository at this point in the history
Category: none
  • Loading branch information
vweevers committed Oct 21, 2024
1 parent a069162 commit 847aac2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 21 additions & 22 deletions test/self.js
Original file line number Diff line number Diff line change
@@ -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')({
Expand Down Expand Up @@ -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 } })
Expand All @@ -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 } })

Expand All @@ -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 } })

Expand All @@ -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,
Expand All @@ -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 } })

Expand All @@ -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 } })

Expand Down Expand Up @@ -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 })
Expand All @@ -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 })
Expand All @@ -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 })
Expand All @@ -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'
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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 } })

Expand All @@ -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 } })
Expand Down Expand Up @@ -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 } })

Expand All @@ -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 } })

Expand Down Expand Up @@ -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 })
Expand All @@ -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()
Expand All @@ -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()

Expand All @@ -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 } })

Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { AbstractLevel, AbstractChainedBatch } = require('..')
const { AbstractIterator, AbstractKeyIterator, AbstractValueIterator } = require('..')
const noop = function () {}

exports.illegalKeys = [
{ name: 'null key', key: null },
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 847aac2

Please sign in to comment.