1
1
'use strict'
2
2
3
3
const test = require ( 'tape' )
4
- const sinon = require ( 'sinon' )
5
4
const isBuffer = require ( 'is-buffer' )
6
5
const { Buffer } = require ( 'buffer' )
7
6
const { AbstractLevel, AbstractChainedBatch } = require ( '..' )
8
- const { MinimalLevel } = require ( './util' )
7
+ const { MinimalLevel, createSpy } = require ( './util' )
9
8
const getRangeOptions = require ( '../lib/range-options' )
10
9
11
10
const testCommon = require ( './common' ) ( {
@@ -55,7 +54,7 @@ test('manifest is required', function (t) {
55
54
} )
56
55
57
56
test ( 'test open() extensibility when new' , async function ( t ) {
58
- const spy = sinon . spy ( async function ( ) { } )
57
+ const spy = createSpy ( async function ( ) { } )
59
58
const expectedOptions = { createIfMissing : true , errorIfExists : false }
60
59
const Test = implement ( AbstractLevel , { _open : spy } )
61
60
const test = new Test ( { encodings : { utf8 : true } } )
@@ -81,7 +80,7 @@ test('test open() extensibility when new', async function (t) {
81
80
test ( 'test open() extensibility when open' , function ( t ) {
82
81
t . plan ( 2 )
83
82
84
- const spy = sinon . spy ( async function ( ) { } )
83
+ const spy = createSpy ( async function ( ) { } )
85
84
const Test = implement ( AbstractLevel , { _open : spy } )
86
85
const test = new Test ( { encodings : { utf8 : true } } )
87
86
@@ -97,7 +96,7 @@ test('test open() extensibility when open', function (t) {
97
96
test ( 'test opening explicitly gives a chance to capture an error' , async function ( t ) {
98
97
t . plan ( 3 )
99
98
100
- const spy = sinon . spy ( async function ( options ) { throw new Error ( '_open error' ) } )
99
+ const spy = createSpy ( async function ( options ) { throw new Error ( '_open error' ) } )
101
100
const Test = implement ( AbstractLevel , { _open : spy } )
102
101
const test = new Test ( { encodings : { utf8 : true } } )
103
102
@@ -111,7 +110,7 @@ test('test opening explicitly gives a chance to capture an error', async functio
111
110
} )
112
111
113
112
test ( 'test constructor options are forwarded to open()' , async function ( t ) {
114
- const spy = sinon . spy ( async function ( options ) { } )
113
+ const spy = createSpy ( async function ( options ) { } )
115
114
const Test = implement ( AbstractLevel , { _open : spy } )
116
115
const test = new Test ( { encodings : { utf8 : true } } , {
117
116
passive : true ,
@@ -132,7 +131,7 @@ test('test constructor options are forwarded to open()', async function (t) {
132
131
} )
133
132
134
133
test ( 'test close() extensibility when open' , async function ( t ) {
135
- const spy = sinon . spy ( async function ( ) { } )
134
+ const spy = createSpy ( async function ( ) { } )
136
135
const Test = implement ( AbstractLevel , { _close : spy } )
137
136
const test = new Test ( { encodings : { utf8 : true } } )
138
137
@@ -145,7 +144,7 @@ test('test close() extensibility when open', async function (t) {
145
144
} )
146
145
147
146
test ( 'test close() extensibility when new' , async function ( t ) {
148
- const spy = sinon . spy ( async function ( ) { } )
147
+ const spy = createSpy ( async function ( ) { } )
149
148
const Test = implement ( AbstractLevel , { _close : spy } )
150
149
const test = new Test ( { encodings : { utf8 : true } } )
151
150
@@ -288,7 +287,7 @@ test('open() error is combined with resource error', async function (t) {
288
287
} )
289
288
290
289
test ( 'test get() extensibility' , async function ( t ) {
291
- const spy = sinon . spy ( async function ( ) { } )
290
+ const spy = createSpy ( async function ( ) { } )
292
291
const expectedOptions = { keyEncoding : 'utf8' , valueEncoding : 'utf8' }
293
292
const expectedKey = 'a key'
294
293
const Test = implement ( AbstractLevel , { _get : spy } )
@@ -314,7 +313,7 @@ test('test get() extensibility', async function (t) {
314
313
} )
315
314
316
315
test ( 'test getMany() extensibility' , async function ( t ) {
317
- const spy = sinon . spy ( async ( ) => [ 'x' ] )
316
+ const spy = createSpy ( async ( ) => [ 'x' ] )
318
317
const expectedOptions = { keyEncoding : 'utf8' , valueEncoding : 'utf8' }
319
318
const expectedKey = 'a key'
320
319
const Test = implement ( AbstractLevel , { _getMany : spy } )
@@ -340,7 +339,7 @@ test('test getMany() extensibility', async function (t) {
340
339
} )
341
340
342
341
test ( 'test del() extensibility' , async function ( t ) {
343
- const spy = sinon . spy ( async function ( ) { } )
342
+ const spy = createSpy ( async function ( ) { } )
344
343
const expectedOptions = { options : 1 , keyEncoding : 'utf8' }
345
344
const expectedKey = 'a key'
346
345
const Test = implement ( AbstractLevel , { _del : spy } )
@@ -365,7 +364,7 @@ test('test del() extensibility', async function (t) {
365
364
} )
366
365
367
366
test ( 'test put() extensibility' , async function ( t ) {
368
- const spy = sinon . spy ( async function ( ) { } )
367
+ const spy = createSpy ( async function ( ) { } )
369
368
const expectedOptions = { options : 1 , keyEncoding : 'utf8' , valueEncoding : 'utf8' }
370
369
const expectedKey = 'a key'
371
370
const expectedValue = 'a value'
@@ -393,7 +392,7 @@ test('test put() extensibility', async function (t) {
393
392
} )
394
393
395
394
test ( 'batch([]) extensibility' , async function ( t ) {
396
- const spy = sinon . spy ( async function ( ) { } )
395
+ const spy = createSpy ( async function ( ) { } )
397
396
const expectedOptions = { options : 1 }
398
397
const expectedArray = [
399
398
{ type : 'put' , key : '1' , value : '1' , keyEncoding : 'utf8' , valueEncoding : 'utf8' } ,
@@ -431,7 +430,7 @@ test('batch([]) extensibility', async function (t) {
431
430
test ( 'batch([]) with empty array is a noop' , function ( t ) {
432
431
t . plan ( 1 )
433
432
434
- const spy = sinon . spy ( )
433
+ const spy = createSpy ( )
435
434
const Test = implement ( AbstractLevel , { _batch : spy } )
436
435
const test = new Test ( { encodings : { utf8 : true } } )
437
436
@@ -443,7 +442,7 @@ test('batch([]) with empty array is a noop', function (t) {
443
442
} )
444
443
445
444
test ( 'test chained batch() extensibility' , async function ( t ) {
446
- const spy = sinon . spy ( async function ( ) { } )
445
+ const spy = createSpy ( async function ( ) { } )
447
446
const expectedOptions = { options : 1 }
448
447
const Test = implement ( AbstractLevel , { _batch : spy } )
449
448
const test = new Test ( { encodings : { utf8 : true } } )
@@ -473,7 +472,7 @@ test('test chained batch() extensibility', async function (t) {
473
472
test ( 'test chained batch() with no operations is a noop' , function ( t ) {
474
473
t . plan ( 1 )
475
474
476
- const spy = sinon . spy ( async function ( ) { } )
475
+ const spy = createSpy ( async function ( ) { } )
477
476
const Test = implement ( AbstractLevel , { _batch : spy } )
478
477
const test = new Test ( { encodings : { utf8 : true } } )
479
478
@@ -485,7 +484,7 @@ test('test chained batch() with no operations is a noop', function (t) {
485
484
} )
486
485
487
486
test ( 'test chained batch() (custom _chainedBatch) extensibility' , async function ( t ) {
488
- const spy = sinon . spy ( )
487
+ const spy = createSpy ( )
489
488
const Test = implement ( AbstractLevel , { _chainedBatch : spy } )
490
489
const test = new Test ( { encodings : { utf8 : true } } )
491
490
@@ -583,7 +582,7 @@ test('test AbstractChainedBatch#write() extensibility with options', async funct
583
582
test ( 'test AbstractChainedBatch#put() extensibility' , function ( t ) {
584
583
t . plan ( 8 )
585
584
586
- const spy = sinon . spy ( )
585
+ const spy = createSpy ( )
587
586
const expectedKey = 'key'
588
587
const expectedValue = 'value'
589
588
const Test = implement ( AbstractChainedBatch , { _put : spy } )
@@ -610,7 +609,7 @@ test('test AbstractChainedBatch#put() extensibility', function (t) {
610
609
test ( 'test AbstractChainedBatch#del() extensibility' , function ( t ) {
611
610
t . plan ( 6 )
612
611
613
- const spy = sinon . spy ( )
612
+ const spy = createSpy ( )
614
613
const expectedKey = 'key'
615
614
const Test = implement ( AbstractChainedBatch , { _del : spy } )
616
615
const db = testCommon . factory ( )
@@ -634,7 +633,7 @@ test('test AbstractChainedBatch#del() extensibility', function (t) {
634
633
test ( 'test AbstractChainedBatch#clear() extensibility' , function ( t ) {
635
634
t . plan ( 4 )
636
635
637
- const spy = sinon . spy ( )
636
+ const spy = createSpy ( )
638
637
const Test = implement ( AbstractChainedBatch , { _clear : spy } )
639
638
const db = testCommon . factory ( )
640
639
@@ -652,7 +651,7 @@ test('test AbstractChainedBatch#clear() extensibility', function (t) {
652
651
test ( 'test clear() extensibility' , async function ( t ) {
653
652
t . plan ( ( 7 * 4 ) - 3 )
654
653
655
- const spy = sinon . spy ( )
654
+ const spy = createSpy ( )
656
655
const Test = implement ( AbstractLevel , { _clear : spy } )
657
656
const db = new Test ( { encodings : { utf8 : true } } )
658
657
@@ -685,7 +684,7 @@ test('test clear() extensibility', async function (t) {
685
684
test . skip ( 'test serialization extensibility (batch array is not mutated)' , function ( t ) {
686
685
t . plan ( 7 )
687
686
688
- const spy = sinon . spy ( )
687
+ const spy = createSpy ( )
689
688
const Test = implement ( AbstractLevel , {
690
689
_batch : spy ,
691
690
_serializeKey : function ( key ) {
0 commit comments