diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 144fd6ca..bd744c3c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,9 +7,7 @@ updates: ignore: - dependency-name: dependency-check - dependency-name: sinon - - dependency-name: airtap - dependency-name: nyc - - dependency-name: standard # Pinned to 1.1.10 for browser compatibility (later versions depend # on `queue-microtask` which uses arrow functions and promises). diff --git a/lib/batch.js b/lib/batch.js index bc43f95d..59565c3e 100644 --- a/lib/batch.js +++ b/lib/batch.js @@ -1,7 +1,9 @@ -var WriteError = require('level-errors').WriteError -var catering = require('catering') -var getCallback = require('./common').getCallback -var getOptions = require('./common').getOptions +'use strict' + +const WriteError = require('level-errors').WriteError +const catering = require('catering') +const getCallback = require('./common').getCallback +const getOptions = require('./common').getOptions function Batch (levelup) { // TODO (next major): remove this._levelup alias @@ -18,7 +20,7 @@ Batch.prototype.put = function (key, value) { throw new WriteError(e) } - this.ops.push({ type: 'put', key: key, value: value }) + this.ops.push({ type: 'put', key, value }) this.length++ return this @@ -31,7 +33,7 @@ Batch.prototype.del = function (key) { throw new WriteError(err) } - this.ops.push({ type: 'del', key: key }) + this.ops.push({ type: 'del', key }) this.length++ return this @@ -51,8 +53,8 @@ Batch.prototype.clear = function () { } Batch.prototype.write = function (options, callback) { - var levelup = this._levelup - var ops = this.ops + const levelup = this._levelup + const ops = this.ops callback = getCallback(options, callback) callback = catering.fromCallback(callback) diff --git a/lib/common.js b/lib/common.js index 5096de81..c354fa86 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,3 +1,5 @@ +'use strict' + exports.getCallback = function (options, callback) { return typeof options === 'function' ? options : callback } diff --git a/lib/levelup.js b/lib/levelup.js index 57917dc8..fab316f4 100644 --- a/lib/levelup.js +++ b/lib/levelup.js @@ -1,21 +1,23 @@ -var EventEmitter = require('events').EventEmitter -var inherits = require('util').inherits -var extend = require('xtend') -var DeferredLevelDOWN = require('deferred-leveldown') -var IteratorStream = require('level-iterator-stream') -var Batch = require('./batch') -var errors = require('level-errors') -var supports = require('level-supports') -var assert = require('assert') -var catering = require('catering') -var getCallback = require('./common').getCallback -var getOptions = require('./common').getOptions - -var WriteError = errors.WriteError -var ReadError = errors.ReadError -var NotFoundError = errors.NotFoundError -var OpenError = errors.OpenError -var InitializationError = errors.InitializationError +'use strict' + +const EventEmitter = require('events').EventEmitter +const inherits = require('util').inherits +const extend = require('xtend') +const DeferredLevelDOWN = require('deferred-leveldown') +const IteratorStream = require('level-iterator-stream') +const Batch = require('./batch') +const errors = require('level-errors') +const supports = require('level-supports') +const assert = require('assert') +const catering = require('catering') +const getCallback = require('./common').getCallback +const getOptions = require('./common').getOptions + +const WriteError = errors.WriteError +const ReadError = errors.ReadError +const NotFoundError = errors.NotFoundError +const OpenError = errors.OpenError +const InitializationError = errors.InitializationError // Possible AbstractLevelDOWN#status values: // - 'new' - newly created, not opened or closed @@ -30,8 +32,7 @@ function LevelUP (db, options, callback) { return new LevelUP(db, options, callback) } - var error - var self = this + let error EventEmitter.call(this) this.setMaxListeners(Infinity) @@ -56,9 +57,9 @@ function LevelUP (db, options, callback) { this.options = getOptions(options) this._db = db this.db = new DeferredLevelDOWN(db) - this.open(callback || function (err) { - if (err) self.emit('error', err) - }) + this.open(callback || ((err) => { + if (err) this.emit('error', err) + })) // Create manifest based on deferred-leveldown's this.supports = supports(this.db.supports, { @@ -70,14 +71,14 @@ function LevelUP (db, options, callback) { }) // Experimental: enrich levelup interface - Object.keys(this.supports.additionalMethods).forEach(function (method) { - if (this[method] != null) return + for (const method of Object.keys(this.supports.additionalMethods)) { + if (this[method] != null) continue // Don't do this.db[method].bind() because this.db is dynamic. - this[method] = function () { - return this.db[method].apply(this.db, arguments) + this[method] = function (...args) { + return this.db[method](...args) } - }, this) + } } LevelUP.prototype.emit = EventEmitter.prototype.emit @@ -85,8 +86,6 @@ LevelUP.prototype.once = EventEmitter.prototype.once inherits(LevelUP, EventEmitter) LevelUP.prototype.open = function (opts, callback) { - var self = this - if (typeof opts === 'function') { callback = opts opts = null @@ -99,39 +98,37 @@ LevelUP.prototype.open = function (opts, callback) { } if (this.isOpen()) { - process.nextTick(callback, null, self) + process.nextTick(callback, null, this) return callback.promise } if (this._isOpening()) { - this.once('open', function () { callback(null, self) }) + this.once('open', () => { callback(null, this) }) return callback.promise } this.emit('opening') - this.db.open(opts, function (err) { + this.db.open(opts, (err) => { if (err) { return callback(new OpenError(err)) } - self.db = self._db - callback(null, self) - self.emit('open') - self.emit('ready') + this.db = this._db + callback(null, this) + this.emit('open') + this.emit('ready') }) return callback.promise } LevelUP.prototype.close = function (callback) { - var self = this - callback = catering.fromCallback(callback) if (this.isOpen()) { - this.db.close(function () { - self.emit('closed') - callback.apply(null, arguments) + this.db.close((err, ...rest) => { + this.emit('closed') + callback(err, ...rest) }) this.emit('closing') this.db = new DeferredLevelDOWN(this._db) @@ -140,8 +137,8 @@ LevelUP.prototype.close = function (callback) { } else if (this.db.status === 'closing') { this.once('closed', callback) } else if (this._isOpening()) { - this.once('open', function () { - self.close(callback) + this.once('open', () => { + this.close(callback) }) } @@ -186,8 +183,6 @@ LevelUP.prototype.get = function (key, options, callback) { } LevelUP.prototype.put = function (key, value, options, callback) { - var self = this - callback = getCallback(options, callback) callback = catering.fromCallback(callback) @@ -197,11 +192,11 @@ LevelUP.prototype.put = function (key, value, options, callback) { options = getOptions(options) - this.db.put(key, value, options, function (err) { + this.db.put(key, value, options, (err) => { if (err) { return callback(new WriteError(err)) } - self.emit('put', key, value) + this.emit('put', key, value) callback() }) @@ -209,8 +204,6 @@ LevelUP.prototype.put = function (key, value, options, callback) { } LevelUP.prototype.del = function (key, options, callback) { - var self = this - callback = getCallback(options, callback) callback = catering.fromCallback(callback) @@ -220,11 +213,11 @@ LevelUP.prototype.del = function (key, options, callback) { options = getOptions(options) - this.db.del(key, options, function (err) { + this.db.del(key, options, (err) => { if (err) { return callback(new WriteError(err)) } - self.emit('del', key) + this.emit('del', key) callback() }) @@ -236,8 +229,6 @@ LevelUP.prototype.batch = function (arr, options, callback) { return new Batch(this) } - var self = this - if (typeof arr === 'function') callback = arr else callback = getCallback(options, callback) @@ -249,11 +240,11 @@ LevelUP.prototype.batch = function (arr, options, callback) { options = getOptions(options) - this.db.batch(arr, options, function (err) { + this.db.batch(arr, options, (err) => { if (err) { return callback(new WriteError(err)) } - self.emit('batch', arr) + this.emit('batch', arr) callback() }) @@ -265,8 +256,6 @@ LevelUP.prototype.iterator = function (options) { } LevelUP.prototype.clear = function (options, callback) { - var self = this - callback = getCallback(options, callback) options = getOptions(options) callback = catering.fromCallback(callback) @@ -275,11 +264,11 @@ LevelUP.prototype.clear = function (options, callback) { return callback.promise } - this.db.clear(options, function (err) { + this.db.clear(options, (err) => { if (err) { return callback(new WriteError(err)) } - self.emit('clear', options) + this.emit('clear', options) callback() }) diff --git a/package.json b/package.json index e8cbcd69..446daeda 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "safe-buffer": "^5.1.0", "simple-concat": "^1.0.0", "sinon": "^7.4.2", - "standard": "^15.0.0", + "standard": "^16.0.3", "tape": "^5.2.2", "trickle": "0.0.2" }, diff --git a/test/batch-test.js b/test/batch-test.js index c66a4bd3..0d9a1148 100644 --- a/test/batch-test.js +++ b/test/batch-test.js @@ -1,8 +1,8 @@ -var levelup = require('../lib/levelup') -var errors = levelup.errors -var each = require('async-each') -var series = require('run-series') -var discardable = require('./util/discardable') +const levelup = require('../lib/levelup') +const errors = levelup.errors +const each = require('async-each') +const series = require('run-series') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('array-form batch(): multiple puts', function (t) { @@ -124,11 +124,11 @@ module.exports = function (test, testCommon) { test('chained batch(): options', function (t) { discardable(t, testCommon, function (db, done) { - var batch = db.batch() - var underlying = batch + const batch = db.batch() + let underlying = batch while (underlying.batch) underlying = underlying.batch - var write = underlying.write.bind(underlying) + const write = underlying.write.bind(underlying) underlying.write = function (options, cb) { t.same(options, { foo: 'bar' }) write(options, cb) @@ -144,9 +144,9 @@ module.exports = function (test, testCommon) { testCommon.promises && test('chained batch(): promise interface - options', function (t) { discardable(t, testCommon, function (db, done) { - var batch = db.batch() + const batch = db.batch() - var write = batch.batch.write.bind(batch.batch) + const write = batch.batch.write.bind(batch.batch) batch.batch.write = function (options, cb) { t.same(options, { foo: 'bar' }) write(options, cb) @@ -194,7 +194,7 @@ module.exports = function (test, testCommon) { test('chained batch(): exposes ops queue length', function (t) { discardable(t, testCommon, function (db, done) { - var batch = db.batch() + const batch = db.batch() .put('one', '1') .del('two') .put('three', '3') @@ -288,7 +288,7 @@ module.exports = function (test, testCommon) { test('chained batch() arguments', function (t) { discardable(t, testCommon, function (db, done) { - var batch = db.batch() + const batch = db.batch() t.test('chained batch() arguments: batch#put() with missing `value`', function (t) { throws(t, batch.put.bind(batch, 'foo1'), function (err) { @@ -360,7 +360,7 @@ module.exports = function (test, testCommon) { t.is(err.message, 'write() already called on this batch') } - var batch = db.batch() + const batch = db.batch() batch.put('foo', 'bar').put('boom', 'bang').del('foo').write(function (err) { t.ifError(err, 'no batch error') diff --git a/test/benchmarks/engines/levelup-release.js b/test/benchmarks/engines/levelup-release.js index b30a6c1d..dbfb50b6 100644 --- a/test/benchmarks/engines/levelup-release.js +++ b/test/benchmarks/engines/levelup-release.js @@ -1,13 +1,13 @@ -var levelup = require('levelup') -var leveldown = require('leveldown') +const levelup = require('levelup') +const leveldown = require('leveldown') -var createDb = function (location, callback) { +const createDb = function (location, callback) { levelup(leveldown(location), function (err, db) { setTimeout(callback.bind(null, err, db), 50) }) } -var closeDb = function (db, callback) { +const closeDb = function (db, callback) { db.close(callback) } diff --git a/test/benchmarks/engines/levelup.js b/test/benchmarks/engines/levelup.js index cddff347..029d8fcb 100644 --- a/test/benchmarks/engines/levelup.js +++ b/test/benchmarks/engines/levelup.js @@ -1,13 +1,13 @@ -var levelup = require('../../../') -var leveldown = require('leveldown') +const levelup = require('../../../') +const leveldown = require('leveldown') -var createDb = function (location, callback) { +const createDb = function (location, callback) { levelup(leveldown(location), function (err, db) { setTimeout(callback.bind(null, err, db), 50) }) } -var closeDb = function (db, callback) { +const closeDb = function (db, callback) { db.close(callback) } diff --git a/test/benchmarks/engines/sqlite3.js b/test/benchmarks/engines/sqlite3.js index 8fd5b542..8558ae56 100644 --- a/test/benchmarks/engines/sqlite3.js +++ b/test/benchmarks/engines/sqlite3.js @@ -1,7 +1,7 @@ -var sqlite3 = require('sqlite3') +const sqlite3 = require('sqlite3') -var createDb = function (location, callback) { - var db = new sqlite3.Database(location, function (err) { +const createDb = function (location, callback) { + const db = new sqlite3.Database(location, function (err) { if (err) return callback(err) db.run('CREATE TABLE bench (key VARCHAR(32), value TEXT)', function (err) { if (err) return callback(err) @@ -10,7 +10,7 @@ var createDb = function (location, callback) { }) } -var closeDb = function (db, callback) { +const closeDb = function (db, callback) { db.close() // does it have a callback? setTimeout(callback, 50) } diff --git a/test/benchmarks/index.js b/test/benchmarks/index.js index ecac837c..46f25a3a 100644 --- a/test/benchmarks/index.js +++ b/test/benchmarks/index.js @@ -1,33 +1,33 @@ -var DB_ROOT = __dirname -var path = require('path') -var Benchmark = require('benchmark') -var rimraf = require('rimraf') -var async = require('async') -var engines = require('./engines/') -var tests = require('./tests/') +const DB_ROOT = __dirname +const path = require('path') +const Benchmark = require('benchmark') +const rimraf = require('rimraf') +const async = require('async') +const engines = require('./engines/') +let tests = require('./tests/') -var dbidx = 0 +let dbidx = 0 -var printableEngineName = function (engineName) { - var len = Object.keys(engines).reduce(function (m, c) { return Math.max(c.length, m) }, 0) +const printableEngineName = function (engineName) { + const len = Object.keys(engines).reduce(function (m, c) { return Math.max(c.length, m) }, 0) while (engineName.length < len) engineName += ' ' return engineName } -var mklocation = function () { +const mklocation = function () { return path.join(DB_ROOT, '_benchdb_' + dbidx++) } -var mkdb = function (engine, location, callback) { +const mkdb = function (engine, location, callback) { rimraf(location, engine.createDb.bind(null, location, callback)) } -var rmdb = function (engine, db, location, callback) { +const rmdb = function (engine, db, location, callback) { engine.closeDb(db, rimraf.bind(null, location, callback)) } -var run = function (db, name, fn, color, cb) { - var exec = function () { +const run = function (db, name, fn, color, cb) { + const exec = function () { new Benchmark(name, { defer: true, fn: function (deferred) { @@ -49,11 +49,11 @@ var run = function (db, name, fn, color, cb) { } else { exec() } } -var runTest = function (testName, callback) { +const runTest = function (testName, callback) { async.forEachSeries( Object.keys(engines), function (engineKey, callback) { - var engine = engines[engineKey] - var location = mklocation() + const engine = engines[engineKey] + const location = mklocation() mkdb(engine, location, function (err, db) { if (err) return callback(err) if (!tests[testName][engineKey]) { console.log('Skipping for', testName, engineKey); return callback() } @@ -74,10 +74,10 @@ var runTest = function (testName, callback) { ) } -var focusKey = Object.keys(tests).filter(function (k) { return (/=>/).test(k) }) +const focusKey = Object.keys(tests).filter(function (k) { return (/=>/).test(k) }) if (focusKey.length) { - var focusTest = tests[focusKey[0]] + const focusTest = tests[focusKey[0]] tests = {} tests[focusKey[0]] = focusTest } diff --git a/test/benchmarks/stream-bench.js b/test/benchmarks/stream-bench.js index b52f7e90..aa375530 100644 --- a/test/benchmarks/stream-bench.js +++ b/test/benchmarks/stream-bench.js @@ -1,13 +1,13 @@ -var levelup = require(process.argv[2] || '../../') -var crypto = require('crypto') -var srcdb = levelup('/tmp/source.db') +const levelup = require(process.argv[2] || '../../') +const crypto = require('crypto') +const srcdb = levelup('/tmp/source.db') -var batch = 10000 -var total = 200000 +const batch = 10000 +const total = 200000 function fillBatch (start, callback) { - var b = [] - for (var i = start; i < start + batch; i++) { + const b = [] + for (let i = start; i < start + batch; i++) { b.push({ type: 'put', key: i, value: crypto.randomBytes(100) }) } srcdb.batch(b, callback) @@ -22,10 +22,10 @@ function populate (start, callback) { } srcdb.on('ready', function () { - var start = Date.now() + const start = Date.now() populate(0, function () { - var batchTime = Date.now() - start + const batchTime = Date.now() - start console.log('Filled source! Took %sms, reading data now...', batchTime) run(function () { @@ -47,10 +47,10 @@ function run (cb) { } function stream (opts, cb) { - var start = Date.now() + const start = Date.now() srcdb.createReadStream() .on('end', function () { - var copyTime = Date.now() - start + const copyTime = Date.now() - start console.log('Done! Took %sms with %j', copyTime, opts) if (cb) cb() }) diff --git a/test/benchmarks/tests/batch_int_string_x1000_levelup.js b/test/benchmarks/tests/batch_int_string_x1000_levelup.js index 4214d1a6..7e53965f 100644 --- a/test/benchmarks/tests/batch_int_string_x1000_levelup.js +++ b/test/benchmarks/tests/batch_int_string_x1000_levelup.js @@ -1,14 +1,14 @@ -var fn = function (puts, db, cb) { - var after = function (err) { +const fn = function (puts, db, cb) { + const after = function (err) { if (err) throw err cb() } - var data = [] + const data = [] if (this.cycle == null) this.cycle = 0 else this.cycle++ - for (var i = 0; i < puts; i++) { + for (let i = 0; i < puts; i++) { data.push({ type: 'put', key: this.cycle * puts + i, diff --git a/test/benchmarks/tests/get_int_string_x1000_levelup.js b/test/benchmarks/tests/get_int_string_x1000_levelup.js index 107cc2ed..205b979e 100644 --- a/test/benchmarks/tests/get_int_string_x1000_levelup.js +++ b/test/benchmarks/tests/get_int_string_x1000_levelup.js @@ -1,7 +1,7 @@ -var setupFn = function (count, db, cb) { - var data = [] +const setupFn = function (count, db, cb) { + const data = [] - for (var i = 0; i < count; i++) { + for (let i = 0; i < count; i++) { data.push({ type: 'put', key: String(i), @@ -12,13 +12,13 @@ var setupFn = function (count, db, cb) { db.batch(data, cb) } -var fn = function (count, db, cb) { - var received = 0 - var after = function (err) { +const fn = function (count, db, cb) { + let received = 0 + const after = function (err) { if (err) throw err if (++received === count) cb() } - for (var i = 0; i < count; i++) { db.get(String(i), after) } + for (let i = 0; i < count; i++) { db.get(String(i), after) } } module.exports = fn.bind(null, 1000) diff --git a/test/benchmarks/tests/get_int_string_x1000_sqlite3.js b/test/benchmarks/tests/get_int_string_x1000_sqlite3.js index fb42605c..9f3e0b7b 100644 --- a/test/benchmarks/tests/get_int_string_x1000_sqlite3.js +++ b/test/benchmarks/tests/get_int_string_x1000_sqlite3.js @@ -1,7 +1,7 @@ -var async = require('async') +const async = require('async') -var setupFn = function (count, db, cb) { - var queue = async.queue(function (key, callback) { +const setupFn = function (count, db, cb) { + const queue = async.queue(function (key, callback) { db.exec( 'INSERT INTO bench VALUES(' + key + @@ -10,16 +10,16 @@ var setupFn = function (count, db, cb) { , callback) }, 20) queue.drain = cb - for (var i = 0; i < count; i++) { queue.push(String(i)) } + for (let i = 0; i < count; i++) { queue.push(String(i)) } } -var fn = function (count, db, cb) { - var received = 0 - var after = function (err) { +const fn = function (count, db, cb) { + let received = 0 + const after = function (err) { if (err) throw err if (++received === count) cb() } - for (var i = 0; i < count; i++) { db.get('SELECT value FROM bench WHERE key = "' + i + '"', after) } + for (let i = 0; i < count; i++) { db.get('SELECT value FROM bench WHERE key = "' + i + '"', after) } } module.exports = fn.bind(null, 1000) diff --git a/test/benchmarks/tests/put_int_string_x1000_levelup.js b/test/benchmarks/tests/put_int_string_x1000_levelup.js index 6039fec4..8b7f18c3 100644 --- a/test/benchmarks/tests/put_int_string_x1000_levelup.js +++ b/test/benchmarks/tests/put_int_string_x1000_levelup.js @@ -1,6 +1,6 @@ -var fn = function (puts, db, cb) { - var received = 0 - var after = function (err) { +const fn = function (puts, db, cb) { + let received = 0 + const after = function (err) { if (err) throw err if (++received === puts) cb() } @@ -8,7 +8,7 @@ var fn = function (puts, db, cb) { if (this.cycle == null) this.cycle = 0 else this.cycle++ - for (var i = 0; i < puts; i++) { + for (let i = 0; i < puts; i++) { db.put( String(this.cycle * puts + i), 'It\'ll be top end no worries stands out like a bushie. It\'ll be cream no dramas flat out like a rotten. As busy as a slabs bloody built like a stonkered. Get a dog up ya oldies no dramas lets get some bottle-o. Built like a schooner as busy as a big smoke. You little ripper ute my you little ripper dag.', diff --git a/test/benchmarks/tests/put_int_string_x1000_sqlite3.js b/test/benchmarks/tests/put_int_string_x1000_sqlite3.js index f24c9e66..7820fded 100644 --- a/test/benchmarks/tests/put_int_string_x1000_sqlite3.js +++ b/test/benchmarks/tests/put_int_string_x1000_sqlite3.js @@ -1,6 +1,6 @@ -var fn = function (puts, db, cb) { - var received = 0 - var after = function (err) { +const fn = function (puts, db, cb) { + let received = 0 + const after = function (err) { if (err) throw err if (++received === puts) cb() } @@ -8,7 +8,7 @@ var fn = function (puts, db, cb) { if (this.cycle == null) this.cycle = 0 else this.cycle++ - for (var i = 0; i < puts; i++) { + for (let i = 0; i < puts; i++) { db.exec( 'INSERT INTO bench VALUES(' + String(this.cycle * puts + i) + diff --git a/test/benchmarks/tests/readStream_x100000_levelup.js b/test/benchmarks/tests/readStream_x100000_levelup.js index 785da362..1b7cd8ab 100644 --- a/test/benchmarks/tests/readStream_x100000_levelup.js +++ b/test/benchmarks/tests/readStream_x100000_levelup.js @@ -1,12 +1,12 @@ -var setupFn = function (count, db, cb) { - var doWrites = function () { +const setupFn = function (count, db, cb) { + const doWrites = function () { if (--count === 0) return cb() db.put('aa' + count, 'bb' + count, doWrites) } doWrites() } -var fn = function (db, cb) { +const fn = function (db, cb) { db.createReadStream().on('end', cb) } diff --git a/test/binary-test.js b/test/binary-test.js index 1ce7fa2b..e46d6147 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -1,5 +1,5 @@ -var each = require('async-each') -var discardable = require('./util/discardable') +const each = require('async-each') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('test put() and get() with binary value {valueEncoding:binary}', function (t) { diff --git a/test/browserify-test.js b/test/browserify-test.js index 8aaa8bfd..e50e6e97 100644 --- a/test/browserify-test.js +++ b/test/browserify-test.js @@ -1,13 +1,13 @@ -var browserify = require('browserify') -var path = require('path') -var after = require('after') -var concat = require('simple-concat') -var spawn = require('child_process').spawn -var PACKAGE_JSON = path.join(__dirname, '..', 'package.json') +const browserify = require('browserify') +const path = require('path') +const after = require('after') +const concat = require('simple-concat') +const spawn = require('child_process').spawn +const PACKAGE_JSON = path.join(__dirname, '..', 'package.json') module.exports = function (test) { test('does not contain package.json', function (t) { - var b = browserify(path.join(__dirname, '..'), { browserField: true }) + const b = browserify(path.join(__dirname, '..'), { browserField: true }) .once('error', t.end.bind(t)) b.pipeline .on('file', function (file, id, parent) { @@ -17,9 +17,9 @@ module.exports = function (test) { }) test('throws error if missing db factory', function (t) { - var b = browserify(path.join(__dirname, 'data/browser-throws.js'), { browserField: true }) - var node = spawn('node') - var next = after(2, t.end.bind(t)) + const b = browserify(path.join(__dirname, 'data/browser-throws.js'), { browserField: true }) + const node = spawn('node') + const next = after(2, t.end.bind(t)) concat(node.stderr, function (err, buf) { t.ifError(err) @@ -36,8 +36,8 @@ module.exports = function (test) { }) test('works with valid db factory (memdown)', function (t) { - var b = browserify(path.join(__dirname, 'data/browser-works.js'), { browserField: true }) - var node = spawn('node') + const b = browserify(path.join(__dirname, 'data/browser-works.js'), { browserField: true }) + const node = spawn('node') node.on('exit', function (code) { t.is(code, 0) t.end() diff --git a/test/clear-test.js b/test/clear-test.js index c2d7dcd9..7d984aac 100644 --- a/test/clear-test.js +++ b/test/clear-test.js @@ -1,13 +1,13 @@ -var memdown = require('memdown') -var encode = require('encoding-down') -var concat = require('level-concat-iterator') -var levelup = require('../lib/levelup') +const memdown = require('memdown') +const encode = require('encoding-down') +const concat = require('level-concat-iterator') +const levelup = require('../lib/levelup') module.exports = function (test) { test('clear()', function (t) { function makeTest (name, fn) { t.test(name, function (t) { - var mem = memdown() + const mem = memdown() mem.open(function (err) { t.ifError(err, 'no open error') @@ -36,7 +36,7 @@ module.exports = function (test) { } makeTest('clear() without encoding, without deferred-open', function (t, mem) { - var db = levelup(mem) + const db = levelup(mem) db.open(function (err) { t.ifError(err) @@ -49,7 +49,7 @@ module.exports = function (test) { }) makeTest('clear() without encoding, with deferred-open', function (t, mem) { - var db = levelup(mem) + const db = levelup(mem) db.clear({ gte: '"b"' }, function (err) { t.ifError(err, 'no clear error') @@ -58,7 +58,7 @@ module.exports = function (test) { }) makeTest('clear() with encoding, with deferred-open', function (t, mem) { - var db = levelup(encode(mem, { keyEncoding: 'json' })) + const db = levelup(encode(mem, { keyEncoding: 'json' })) db.clear({ gte: 'b' }, function (err) { t.ifError(err, 'no clear error') @@ -67,7 +67,7 @@ module.exports = function (test) { }) makeTest('clear() with encoding, without deferred-open', function (t, mem) { - var db = levelup(encode(mem, { keyEncoding: 'json' })) + const db = levelup(encode(mem, { keyEncoding: 'json' })) db.open(function (err) { t.ifError(err) diff --git a/test/common.js b/test/common.js index 68cad218..a8a9fa16 100644 --- a/test/common.js +++ b/test/common.js @@ -1,7 +1,7 @@ // Same interface as abstract-leveldown's testCommon module.exports = function testCommon (options) { - var factory = options.factory - var test = options.test + const factory = options.factory + const test = options.test if (typeof factory !== 'function') { throw new TypeError('factory must be a function') diff --git a/test/create-stream-vs-put-racecondition.js b/test/create-stream-vs-put-racecondition.js index 6faab6d4..28b18a78 100644 --- a/test/create-stream-vs-put-racecondition.js +++ b/test/create-stream-vs-put-racecondition.js @@ -1,7 +1,7 @@ -var levelup = require('../lib/levelup') -var memdown = require('memdown') -var encdown = require('encoding-down') -var after = require('after') +const levelup = require('../lib/levelup') +const memdown = require('memdown') +const encdown = require('encoding-down') +const after = require('after') module.exports = function (test, testCommon) { ;[true, false].forEach(function (encode) { @@ -14,7 +14,7 @@ module.exports = function (test, testCommon) { } function makeTest (test, encode, deferredOpen, delayedPut) { - var name = [ + const name = [ 'readStream before put', encode && 'encode', deferredOpen && 'deferred open', @@ -22,8 +22,8 @@ function makeTest (test, encode, deferredOpen, delayedPut) { ].filter(Boolean).join(', ') test(name, function (t) { - var db = encode ? levelup(encdown(memdown())) : levelup(memdown()) - var delay = delayedPut ? process.nextTick : callFn + const db = encode ? levelup(encdown(memdown())) : levelup(memdown()) + const delay = delayedPut ? process.nextTick : callFn run(t, db, !deferredOpen, delay) }) @@ -37,8 +37,8 @@ function run (t, db, explicitOpen, delay) { }) } - var reads = 0 - var next = after(11, function (err) { + let reads = 0 + const next = after(11, function (err) { t.ifError(err, 'no error') t.is(reads, 0, 'got 0 items from snaphot') @@ -58,7 +58,7 @@ function run (t, db, explicitOpen, delay) { // Write data delay(function () { - for (var i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { db.put(String(i), String(i), next) } }) diff --git a/test/custom-encoding-test.js b/test/custom-encoding-test.js index a622d661..39b004b1 100644 --- a/test/custom-encoding-test.js +++ b/test/custom-encoding-test.js @@ -1,5 +1,5 @@ -var each = require('async-each') -var discardable = require('./util/discardable') +const each = require('async-each') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('custom encoding: simple-object values in "json" encoding', function (t) { @@ -61,7 +61,7 @@ module.exports = function (test, testCommon) { }) function run (t, entries) { - var customEncoding = { + const customEncoding = { encode: JSON.stringify, decode: JSON.parse, buffer: false, @@ -72,7 +72,7 @@ module.exports = function (test, testCommon) { keyEncoding: customEncoding, valueEncoding: customEncoding }, function (db, done) { - var ops = entries.map(function (entry) { + const ops = entries.map(function (entry) { return { type: 'put', key: entry.key, value: entry.value } }) diff --git a/test/deferred-open-test.js b/test/deferred-open-test.js index 63c6fe12..b6b465dc 100644 --- a/test/deferred-open-test.js +++ b/test/deferred-open-test.js @@ -1,15 +1,15 @@ -var each = require('async-each') -var parallel = require('run-parallel') -var concat = require('concat-stream') -var readStreamContext = require('./util/rs-context') -var rsFactory = require('./util/rs-factory') +const each = require('async-each') +const parallel = require('run-parallel') +const concat = require('concat-stream') +const readStreamContext = require('./util/rs-context') +const rsFactory = require('./util/rs-factory') module.exports = function (test, testCommon) { - var createReadStream = rsFactory(testCommon) + const createReadStream = rsFactory(testCommon) test('deferred open(): put() and get() on new database', function (t) { // 1) open database without callback, opens in next tick - var db = testCommon.factory() + const db = testCommon.factory() t.ok(typeof db === 'object' && db !== null) parallel([ @@ -41,7 +41,7 @@ module.exports = function (test, testCommon) { test('deferred open(): batch() on new database', function (t) { // 1) open database without callback, opens in next tick - var db = testCommon.factory() + const db = testCommon.factory() t.ok(typeof db === 'object' && db !== null) // 2) insert 3 values with batch(), these should be deferred until the database is actually open @@ -73,7 +73,7 @@ module.exports = function (test, testCommon) { test('deferred open(): chained batch() on new database', function (t) { // 1) open database without callback, opens in next tick - var db = testCommon.factory() + const db = testCommon.factory() t.ok(typeof db === 'object' && db !== null) // 2) insert 3 values with batch(), these should be deferred until the database is actually open @@ -104,14 +104,14 @@ module.exports = function (test, testCommon) { }) testCommon.streams && test('deferred open(): test deferred ReadStream', function (t) { - var ctx = readStreamContext(t) - var db = testCommon.factory() + const ctx = readStreamContext(t) + const db = testCommon.factory() db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) db.close(function (err) { t.ifError(err, 'no error') - var async = true + let async = true db.open(function (err) { async = false @@ -134,15 +134,15 @@ module.exports = function (test, testCommon) { test('deferred open(): no maxListeners warning', function (t) { // 1) open database without callback, opens in next tick - var db = testCommon.factory() - var fail = t.fail.bind(t) + const db = testCommon.factory() + const fail = t.fail.bind(t) process.on('warning', fail) // 2) provoke an EventEmitter maxListeners warning - var toPut = 11 + let toPut = 11 - for (var i = 0; i < toPut; i++) { + for (let i = 0; i < toPut; i++) { db.put('some', 'string', function (err) { t.ifError(err) if (!--toPut) { @@ -154,7 +154,7 @@ module.exports = function (test, testCommon) { }) testCommon.encodings && test('deferred open(): value of queued operation is not serialized', function (t) { - var db = testCommon.factory({ valueEncoding: 'json' }) + const db = testCommon.factory({ valueEncoding: 'json' }) // deferred-leveldown < 2.0.2 would serialize the object to a string. db.put('key', { thing: 2 }, function (err) { @@ -169,7 +169,7 @@ module.exports = function (test, testCommon) { }) testCommon.encodings && test('deferred open(): key of queued operation is not serialized', function (t) { - var db = testCommon.factory({ keyEncoding: 'json' }) + const db = testCommon.factory({ keyEncoding: 'json' }) // deferred-leveldown < 2.0.2 would serialize the key to a string. db.put({ thing: 2 }, 'value', function (err) { diff --git a/test/get-put-del-test.js b/test/get-put-del-test.js index c624193c..16da7f0b 100644 --- a/test/get-put-del-test.js +++ b/test/get-put-del-test.js @@ -1,7 +1,7 @@ -var errors = require('../lib/levelup').errors -var each = require('async-each') -var series = require('run-series') -var discardable = require('./util/discardable') +const errors = require('../lib/levelup').errors +const each = require('async-each') +const series = require('run-series') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('get() / put() / del(): get() on empty database causes error', function (t) { diff --git a/test/idempotent-test.js b/test/idempotent-test.js index 2b90d424..01159ea4 100644 --- a/test/idempotent-test.js +++ b/test/idempotent-test.js @@ -1,14 +1,14 @@ -var levelup = require('../lib/levelup.js') -var memdown = require('memdown') -var sinon = require('sinon') +const levelup = require('../lib/levelup.js') +const memdown = require('memdown') +const sinon = require('sinon') module.exports = function (test, testCommon) { test('call open twice, should emit "open" once', function (t) { - var n = 0 - var m = 0 - var db - var close = function () { - var closing = sinon.spy() + let n = 0 + let m = 0 + + const close = function () { + const closing = sinon.spy() db.on('closing', closing) db.on('closed', function () { t.is(closing.callCount, 1) @@ -21,7 +21,7 @@ module.exports = function (test, testCommon) { process.nextTick(db.close.bind(db)) } - db = levelup(memdown(), function () { + const db = levelup(memdown(), function () { t.is(n++, 0, 'callback should fire only once') if (n && m) { close() } }) diff --git a/test/index.js b/test/index.js index 55fc2a47..6babda94 100644 --- a/test/index.js +++ b/test/index.js @@ -1,10 +1,10 @@ 'use strict' -var common = require('./common') +const common = require('./common') function suite (options) { - var testCommon = common(options) - var test = testCommon.test + const testCommon = common(options) + const test = testCommon.test require('./manifest-test')(test, testCommon) require('./batch-test')(test, testCommon) diff --git a/test/init-test.js b/test/init-test.js index eb114aa7..24078341 100644 --- a/test/init-test.js +++ b/test/init-test.js @@ -1,5 +1,5 @@ -var levelup = require('../lib/levelup') -var memdown = require('memdown') +const levelup = require('../lib/levelup') +const memdown = require('memdown') module.exports = function (test, testCommon) { test('Init & open(): levelup()', function (t) { @@ -38,7 +38,7 @@ module.exports = function (test, testCommon) { }) test('Init & open(): without callback', function (t) { - var db = levelup(memdown()) + const db = levelup(memdown()) t.ok(typeof db === 'object' && db !== null) db.on('ready', function () { t.is(db.isOpen(), true) @@ -49,7 +49,7 @@ module.exports = function (test, testCommon) { test('Init & open(): error with callback', function (t) { t.plan(1) - var mem = memdown() + const mem = memdown() mem._open = function (opts, cb) { process.nextTick(cb, new Error('from underlying store')) } @@ -66,7 +66,7 @@ module.exports = function (test, testCommon) { test('Init & open(): error without callback', function (t) { t.plan(1) - var mem = memdown() + const mem = memdown() mem._open = function (opts, cb) { process.nextTick(cb, new Error('from underlying store')) } @@ -83,7 +83,7 @@ module.exports = function (test, testCommon) { test('Init & open(): validate abstract-leveldown', function (t) { t.plan(1) - var down = memdown() + const down = memdown() Object.defineProperty(down, 'status', { get: function () { return null }, @@ -98,7 +98,7 @@ module.exports = function (test, testCommon) { }) test('Init & open(): support open options', function (t) { - var down = memdown() + const down = memdown() levelup(down, function (err, up) { t.ifError(err, 'no error') diff --git a/test/iterator-seek-test.js b/test/iterator-seek-test.js index edf0dca7..ead23931 100644 --- a/test/iterator-seek-test.js +++ b/test/iterator-seek-test.js @@ -1,10 +1,10 @@ -var memdown = require('memdown') -var encode = require('encoding-down') -var levelup = require('../lib/levelup') +const memdown = require('memdown') +const encode = require('encoding-down') +const levelup = require('../lib/levelup') module.exports = function (test, testCommon) { test('iterator#seek()', function (t) { - var mem = memdown() + const mem = memdown() t.test('setup', function (t) { mem.open(function (err) { @@ -20,12 +20,12 @@ module.exports = function (test, testCommon) { }) t.test('without encoding, without deferred-open', function (t) { - var db = levelup(mem) + const db = levelup(mem) db.open(function (err) { t.ifError(err, 'no open error') - var it = db.iterator({ keyAsBuffer: false }) + const it = db.iterator({ keyAsBuffer: false }) it.seek('"b"') it.next(function (err, key, value) { @@ -40,8 +40,8 @@ module.exports = function (test, testCommon) { }) t.test('without encoding, with deferred-open', function (t) { - var db = levelup(mem) - var it = db.iterator({ keyAsBuffer: false }) + const db = levelup(mem) + const it = db.iterator({ keyAsBuffer: false }) it.seek('"b"') it.next(function (err, key, value) { @@ -55,8 +55,8 @@ module.exports = function (test, testCommon) { }) t.test('with encoding, with deferred-open', function (t) { - var db = levelup(encode(mem, { keyEncoding: 'json' })) - var it = db.iterator() + const db = levelup(encode(mem, { keyEncoding: 'json' })) + const it = db.iterator() it.seek('b') it.next(function (err, key, value) { @@ -70,12 +70,12 @@ module.exports = function (test, testCommon) { }) t.test('with encoding, without deferred-open', function (t) { - var db = levelup(encode(mem, { keyEncoding: 'json' })) + const db = levelup(encode(mem, { keyEncoding: 'json' })) db.open(function (err) { t.ifError(err, 'no open error') - var it = db.iterator() + const it = db.iterator() it.seek('b') it.next(function (err, key, value) { diff --git a/test/iterator-test.js b/test/iterator-test.js index 01e50f70..88d6db47 100644 --- a/test/iterator-test.js +++ b/test/iterator-test.js @@ -1,14 +1,14 @@ -var memdown = require('memdown') -var levelup = require('../lib/levelup') +const memdown = require('memdown') +const levelup = require('../lib/levelup') module.exports = function (test, testCommon) { test('simple iterator without encoding-down', function (t) { - var db = levelup(memdown()) + const db = levelup(memdown()) db.put('key', 'value', function (err) { t.ifError(err, 'no put error') - var it = db.iterator({ + const it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) diff --git a/test/json-encoding-test.js b/test/json-encoding-test.js index ef05e6c9..bcbbda76 100644 --- a/test/json-encoding-test.js +++ b/test/json-encoding-test.js @@ -1,8 +1,8 @@ -var each = require('async-each') -var parallel = require('run-parallel') -var concatStream = require('concat-stream') -var concatIterator = require('level-concat-iterator') -var discardable = require('./util/discardable') +const each = require('async-each') +const parallel = require('run-parallel') +const concatStream = require('concat-stream') +const concatIterator = require('level-concat-iterator') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('json encoding: simple-object values in "json" encoding', function (t) { @@ -56,7 +56,7 @@ module.exports = function (test, testCommon) { keyEncoding: 'json', valueEncoding: 'json' }, function (db, done) { - var ops = entries.map(function (entry) { + const ops = entries.map(function (entry) { return { type: 'put', key: entry.key, value: entry.value } }) diff --git a/test/key-value-streams-test.js b/test/key-value-streams-test.js index aef0a35a..20d5e368 100644 --- a/test/key-value-streams-test.js +++ b/test/key-value-streams-test.js @@ -1,15 +1,15 @@ -var sinon = require('sinon') -var discardable = require('./util/discardable') +const sinon = require('sinon') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('key and value streams: keyStream()', function (t) { - var ctx = createContext(t) + const ctx = createContext(t) discardable(t, testCommon, function (db, done) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = db.keyStream() + const rs = db.keyStream() rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -21,13 +21,13 @@ module.exports = function (test, testCommon) { }) test('key and value streams: readStream({keys:true,values:false})', function (t) { - var ctx = createContext(t) + const ctx = createContext(t) discardable(t, testCommon, function (db, done) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = db.readStream({ keys: true, values: false }) + const rs = db.readStream({ keys: true, values: false }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -39,13 +39,13 @@ module.exports = function (test, testCommon) { }) test('key and value streams: valueStream()', function (t) { - var ctx = createContext(t) + const ctx = createContext(t) discardable(t, testCommon, function (db, done) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = db.valueStream() + const rs = db.valueStream() rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -57,13 +57,13 @@ module.exports = function (test, testCommon) { }) test('key and value streams: readStream({keys:false,values:true})', function (t) { - var ctx = createContext(t) + const ctx = createContext(t) discardable(t, testCommon, function (db, done) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = db.readStream({ keys: false, values: true }) + const rs = db.readStream({ keys: false, values: true }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -76,14 +76,14 @@ module.exports = function (test, testCommon) { } function createContext (t) { - var ctx = {} + const ctx = {} ctx.dataSpy = sinon.spy() ctx.endSpy = sinon.spy() ctx.sourceData = [] - for (var i = 0; i < 100; i++) { - var k = (i < 10 ? '0' : '') + i + for (let i = 0; i < 100; i++) { + const k = (i < 10 ? '0' : '') + i ctx.sourceData.push({ type: 'put', key: k, @@ -101,7 +101,7 @@ function createContext (t) { t.is(ctx.dataSpy.callCount, data.length, 'stream emitted correct number of "data" events') data.forEach(function (d, i) { - var call = ctx.dataSpy.getCall(i) + const call = ctx.dataSpy.getCall(i) if (call) { t.is(call.args.length, 1, 'stream "data" event #' + i + ' fired with 1 argument') diff --git a/test/manifest-test.js b/test/manifest-test.js index fa3704ea..011491ba 100644 --- a/test/manifest-test.js +++ b/test/manifest-test.js @@ -1,11 +1,11 @@ -var suite = require('level-supports/test') +const suite = require('level-supports/test') module.exports = function (test, testCommon) { suite(test, testCommon) // TODO (once manifest lands in other modules): add integration tests. test('manifest has expected properties', function (t) { - var db = testCommon.factory() + const db = testCommon.factory() t.is(db.supports.status, false) t.is(db.supports.deferredOpen, true) diff --git a/test/maybe-error-test.js b/test/maybe-error-test.js index b07613b5..5ecf4fb5 100644 --- a/test/maybe-error-test.js +++ b/test/maybe-error-test.js @@ -1,13 +1,13 @@ 'use strict' -var discardable = require('./util/discardable') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('maybeError() should be called async: put()', function (t) { discardable(t, testCommon, function (db, done) { db.close(function () { t.is(db.isClosed(), true, 'db is closed') - var sync = false + let sync = false db.put('key', 'value', {}, function (err) { sync = true t.ok(err) @@ -25,7 +25,7 @@ module.exports = function (test, testCommon) { t.ifError(err) db.close(function () { t.is(db.isClosed(), true, 'db is closed') - var sync = false + let sync = false db.get('key', {}, function (err, value) { sync = true t.ok(err) @@ -44,7 +44,7 @@ module.exports = function (test, testCommon) { t.ifError(err) db.close(function () { t.is(db.isClosed(), true, 'db is closed') - var sync = false + let sync = false db.del('key', {}, function (err) { sync = true t.ok(err) @@ -61,7 +61,7 @@ module.exports = function (test, testCommon) { discardable(t, testCommon, function (db, done) { db.close(function () { t.is(db.isClosed(), true, 'db is closed') - var sync = false + let sync = false db.batch([{ type: 'put', key: 'key' }], {}, function (err) { sync = true t.ok(err) diff --git a/test/no-encoding-test.js b/test/no-encoding-test.js index fd216eb8..ce313602 100644 --- a/test/no-encoding-test.js +++ b/test/no-encoding-test.js @@ -1,15 +1,15 @@ -var levelup = require('../lib/levelup') -var memdown = require('memdown') +const levelup = require('../lib/levelup') +const memdown = require('memdown') module.exports = function (test, testCommon) { test('without encoding-down: serializes key', function (t) { - var down = memdown() + const down = memdown() down._serializeKey = function (key) { return key.toUpperCase() } - var db = levelup(down) + const db = levelup(down) db.put('key', 'value', function (err) { t.ifError(err) @@ -23,13 +23,13 @@ module.exports = function (test, testCommon) { }) test('without encoding-down: serializes value', function (t) { - var down = memdown() + const down = memdown() down._serializeValue = function (value) { return value.toUpperCase() } - var db = levelup(down) + const db = levelup(down) db.put('key', 'value', function (err) { t.ifError(err) diff --git a/test/null-and-undefined-test.js b/test/null-and-undefined-test.js index 1ea4e30f..65b9e00c 100644 --- a/test/null-and-undefined-test.js +++ b/test/null-and-undefined-test.js @@ -1,10 +1,10 @@ -var after = require('after') -var discardable = require('./util/discardable') +const after = require('after') +const discardable = require('./util/discardable') module.exports = function (test, testCommon) { test('null & undefined keys & values: cause error', function (t) { discardable(t, testCommon, function (db, done) { - var next = after(12, done) + const next = after(12, done) ;[null, undefined].forEach(function (nullish) { db.get(nullish, function (err) { diff --git a/test/open-patchsafe-test.js b/test/open-patchsafe-test.js index 178c6e3a..5aef341c 100644 --- a/test/open-patchsafe-test.js +++ b/test/open-patchsafe-test.js @@ -1,7 +1,7 @@ module.exports = function (test, testCommon) { test('deferred open() is patch-safe: put() on new database', makeTest(function (t, db, done) { - var put = db.put - var called = 0 + const put = db.put + let called = 0 db.put = function () { called++ @@ -15,8 +15,8 @@ module.exports = function (test, testCommon) { })) test('deferred open() is patch-safe: del() on new database', makeTest(function (t, db, done) { - var del = db.del - var called = 0 + const del = db.del + let called = 0 db.del = function () { called++ @@ -30,8 +30,8 @@ module.exports = function (test, testCommon) { })) test('deferred open() is patch-safe: batch() on new database', makeTest(function (t, db, done) { - var batch = db.batch - var called = 0 + const batch = db.batch + let called = 0 db.batch = function () { called++ @@ -50,7 +50,7 @@ module.exports = function (test, testCommon) { function makeTest (fn) { return function (t) { // 1) open database without callback, opens in next tick - var db = testCommon.factory() + const db = testCommon.factory() fn(t, db, function (err) { t.ifError(err, 'no test error') diff --git a/test/read-stream-test.js b/test/read-stream-test.js index 3f3cb179..b1e9dcef 100644 --- a/test/read-stream-test.js +++ b/test/read-stream-test.js @@ -1,11 +1,11 @@ -var sinon = require('sinon') -var bigBlob = Array.apply(null, Array(1024 * 100)).map(function () { return 'aaaaaaaaaa' }).join('') -var discardable = require('./util/discardable') -var readStreamContext = require('./util/rs-context') -var rsFactory = require('./util/rs-factory') +const sinon = require('sinon') +const bigBlob = Array.apply(null, Array(1024 * 100)).map(function () { return 'aaaaaaaaaa' }).join('') +const discardable = require('./util/discardable') +const readStreamContext = require('./util/rs-context') +const rsFactory = require('./util/rs-factory') module.exports = function (test, testCommon) { - var createReadStream = rsFactory(testCommon) + const createReadStream = rsFactory(testCommon) function makeTest (fn) { return function (t) { @@ -19,7 +19,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db) + const rs = createReadStream(db) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -30,14 +30,15 @@ module.exports = function (test, testCommon) { })) test('ReadStream: pausing', makeTest(function (t, db, ctx, done) { - var calls = 0 - var rs - var pauseVerify = function () { + let calls = 0 + let rs + + const pauseVerify = function () { t.is(calls, 5, 'stream should still be paused') rs.resume() pauseVerify.called = true } - var onData = function () { + const onData = function () { if (++calls === 5) { rs.pause() setTimeout(pauseVerify, 50) @@ -66,7 +67,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db) + const rs = createReadStream(db) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -82,7 +83,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db) + const rs = createReadStream(db) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -97,7 +98,7 @@ module.exports = function (test, testCommon) { t.ifError(err) db.close(function (err) { t.ifError(err) - var rs = createReadStream(db) + const rs = createReadStream(db) rs.destroy() done() }) @@ -108,7 +109,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db) + const rs = createReadStream(db) rs.on('data', function () { rs.destroy() rs.destroy() @@ -121,9 +122,9 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db) - var endSpy = sinon.spy() - var calls = 0 + const rs = createReadStream(db) + const endSpy = sinon.spy() + let calls = 0 ctx.dataSpy = sinon.spy(function () { if (++calls === 5) { rs.destroy() } }) @@ -134,7 +135,7 @@ module.exports = function (test, testCommon) { t.is(ctx.dataSpy.callCount, 5, 'ReadStream emitted correct number of "data" events (5)') ctx.sourceData.slice(0, 5).forEach(function (d, i) { - var call = ctx.dataSpy.getCall(i) + const call = ctx.dataSpy.getCall(i) t.ok(call) if (call) { @@ -155,7 +156,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { reverse: true }) + const rs = createReadStream(db, { reverse: true }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -169,7 +170,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: '50' }) + const rs = createReadStream(db, { start: '50' }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -184,7 +185,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: '50', reverse: true }) + const rs = createReadStream(db, { start: '50', reverse: true }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -200,7 +201,7 @@ module.exports = function (test, testCommon) { t.ifError(err) // '49.5' doesn't actually exist but we expect it to start at '50' because '49' < '49.5' < '50' (in string terms as well as numeric) - var rs = createReadStream(db, { start: '49.5' }) + const rs = createReadStream(db, { start: '49.5' }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -215,7 +216,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: '49.5', reverse: true }) + const rs = createReadStream(db, { start: '49.5', reverse: true }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -232,7 +233,7 @@ module.exports = function (test, testCommon) { // '499999' doesn't actually exist but we expect it to start at '50' because '49' < '499999' < '50' (in string terms) // the same as the previous test but we're relying solely on string ordering - var rs = createReadStream(db, { start: '499999' }) + const rs = createReadStream(db, { start: '499999' }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -247,7 +248,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: '50' }) + const rs = createReadStream(db, { end: '50' }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -262,7 +263,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: '50.5' }) + const rs = createReadStream(db, { end: '50.5' }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -277,7 +278,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: '50555555' }) + const rs = createReadStream(db, { end: '50555555' }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -292,7 +293,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: '50.5', reverse: true }) + const rs = createReadStream(db, { end: '50.5', reverse: true }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -306,7 +307,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: 30, end: 70 }) + const rs = createReadStream(db, { start: 30, end: 70 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -321,7 +322,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: 70, end: 30, reverse: true }) + const rs = createReadStream(db, { start: 70, end: 30, reverse: true }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -334,15 +335,15 @@ module.exports = function (test, testCommon) { // TODO: move this test out testCommon.encodings && test('ReadStream: hex encoding', makeTest(function (t, db, ctx, done) { - var options = { keyEncoding: 'utf8', valueEncoding: 'hex' } - var data = [ + const options = { keyEncoding: 'utf8', valueEncoding: 'hex' } + const data = [ { type: 'put', key: 'ab', value: 'abcdef0123456789' } ] db.batch(data.slice(), options, function (err) { t.ifError(err) - var rs = createReadStream(db, options) + const rs = createReadStream(db, options) rs.on('data', function (data) { t.is(data.value, 'abcdef0123456789') }) @@ -355,10 +356,10 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) // read in reverse, assume all's good - var rs = createReadStream(db, { reverse: true }) + const rs = createReadStream(db, { reverse: true }) rs.on('close', function () { // now try reading the other way - var rs = createReadStream(db) + const rs = createReadStream(db) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -374,7 +375,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: 0 }) + const rs = createReadStream(db, { start: 0 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -390,7 +391,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: 0 }) + const rs = createReadStream(db, { end: 0 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -404,15 +405,15 @@ module.exports = function (test, testCommon) { // i.e. not waiting for 'open' to complete // TODO: move this test out testCommon.deferredOpen && test('ReadStream: deferred ReadStream on new db', function (t) { - var db = testCommon.factory() - var ctx = readStreamContext(t) + const db = testCommon.factory() + const ctx = readStreamContext(t) db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) db.close(function (err) { t.ifError(err) - var async = true + let async = true db.open(function (err) { async = false t.ifError(err, 'no open error') @@ -422,7 +423,7 @@ module.exports = function (test, testCommon) { t.is(db.isOpen(), false) t.is(db.isClosed(), false) - var rs = createReadStream(db) + const rs = createReadStream(db) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -440,7 +441,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { limit: 20 }) + const rs = createReadStream(db, { limit: 20 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -454,7 +455,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { start: '20', limit: 20 }) + const rs = createReadStream(db, { start: '20', limit: 20 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -468,7 +469,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: '50', limit: 20 }) + const rs = createReadStream(db, { end: '50', limit: 20 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -482,7 +483,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db, { end: '30', limit: 50 }) + const rs = createReadStream(db, { end: '30', limit: 50 }) rs.on('data', ctx.dataSpy) rs.on('end', ctx.endSpy) rs.on('close', function () { @@ -497,9 +498,9 @@ module.exports = function (test, testCommon) { // the use of large blobs means that next() takes time to return // so we should be able to slip in an end() while it's working test('ReadStream: iterator next/end race condition', makeTest(function (t, db, ctx, done) { - var data = [] - var i = 5 - var v + const data = [] + let i = 5 + let v while (i--) { v = bigBlob + i @@ -508,7 +509,7 @@ module.exports = function (test, testCommon) { db.batch(data, function (err) { t.ifError(err) - var rs = createReadStream(db).on('close', done) + const rs = createReadStream(db).on('close', done) rs.once('data', function () { rs.destroy() }) @@ -519,7 +520,7 @@ module.exports = function (test, testCommon) { db.batch(ctx.sourceData.slice(), function (err) { t.ifError(err) - var rs = createReadStream(db) + const rs = createReadStream(db) .on('close', done) process.nextTick(function () { diff --git a/test/self.js b/test/self.js index 7ccf3bc1..d8e97f38 100644 --- a/test/self.js +++ b/test/self.js @@ -5,12 +5,12 @@ if (process.browser && typeof Promise !== 'function') { global.Promise = require('pinkie') } -var test = require('tape') -var memdown = require('memdown') -var encode = require('encoding-down') -var levelup = require('../lib/levelup') -var suite = require('.') -var noop = function () {} +const test = require('tape') +const memdown = require('memdown') +const encode = require('encoding-down') +const levelup = require('../lib/levelup') +const suite = require('.') +const noop = function () {} suite({ test: test, diff --git a/test/self/manifest-test.js b/test/self/manifest-test.js index 2ab94c62..5945ddaf 100644 --- a/test/self/manifest-test.js +++ b/test/self/manifest-test.js @@ -1,17 +1,17 @@ 'use strict' -var test = require('tape') -var levelup = require('../..') -var memdown = require('memdown') -var sinon = require('sinon') +const test = require('tape') +const levelup = require('../..') +const memdown = require('memdown') +const sinon = require('sinon') test('manifest: additionalMethod is proxied', function (t) { - var mem = memdown() + const mem = memdown() mem.beep = sinon.spy() mem.supports = { additionalMethods: { beep: true } } - var db = levelup(mem) + const db = levelup(mem) t.is(typeof db.beep, 'function') t.is(typeof levelup.prototype.beep, 'undefined') @@ -31,9 +31,9 @@ test('manifest: additionalMethod is proxied', function (t) { }) test('manifest: additionalMethod is proxied even if function does not exist', function (t) { - var mem = memdown() + const mem = memdown() mem.supports = { additionalMethods: { beep: true } } - var db = levelup(mem) + const db = levelup(mem) t.is(typeof db.beep, 'function') t.is(typeof levelup.prototype.beep, 'undefined') @@ -41,7 +41,7 @@ test('manifest: additionalMethod is proxied even if function does not exist', fu }) test('manifest: approximateSize() et al are proxied even if manifest does not exist', function (t) { - var mem = memdown() + const mem = memdown() // deferred-leveldown should feature-detect these methods (for now) mem.approximateSize = function () {} @@ -50,7 +50,7 @@ test('manifest: approximateSize() et al are proxied even if manifest does not ex mem.otherMethod = function () {} mem.supports = null - var db = levelup(mem) + const db = levelup(mem) t.is(typeof db.approximateSize, 'function') t.is(typeof db.compactRange, 'function') diff --git a/test/snapshot-test.js b/test/snapshot-test.js index f216d33c..5f89108a 100644 --- a/test/snapshot-test.js +++ b/test/snapshot-test.js @@ -1,15 +1,15 @@ -var delayed = require('delayed').delayed -var trickle = require('trickle') -var discardable = require('./util/discardable') -var readStreamContext = require('./util/rs-context') -var rsFactory = require('./util/rs-factory') +const delayed = require('delayed').delayed +const trickle = require('trickle') +const discardable = require('./util/discardable') +const readStreamContext = require('./util/rs-context') +const rsFactory = require('./util/rs-factory') module.exports = function (test, testCommon) { - var createReadStream = rsFactory(testCommon) + const createReadStream = rsFactory(testCommon) test('ReadStream implicit snapshot', function (t) { discardable(t, testCommon, function (db, done) { - var ctx = readStreamContext(t) + const ctx = readStreamContext(t) // 1) Store 100 random numbers stored in the database db.batch(ctx.sourceData.slice(), function (err) { @@ -19,7 +19,7 @@ module.exports = function (test, testCommon) { // to make *sure* that we're going to be reading it for longer than it // takes to overwrite the data in there. - var rs = createReadStream(db).pipe(trickle({ interval: 5 })) + const rs = createReadStream(db).pipe(trickle({ interval: 5 })) rs.on('data', ctx.dataSpy) rs.once('end', ctx.endSpy) @@ -33,9 +33,9 @@ module.exports = function (test, testCommon) { // If we're not using a snapshot then then we'd expect the test // to fail because it'll pick up these new values rather than the // old ones. - var newData = [] - var i - var k + const newData = [] + let i + let k for (i = 0; i < 100; i++) { k = (i < 10 ? '0' : '') + i diff --git a/test/util/discardable.js b/test/util/discardable.js index 53fecd06..aa1e3828 100644 --- a/test/util/discardable.js +++ b/test/util/discardable.js @@ -4,7 +4,7 @@ module.exports = function discardable (t, testCommon, options, fn) { options = {} } - var db = testCommon.factory(options) + const db = testCommon.factory(options) db.open(function () { fn(db, function done (err) { diff --git a/test/util/rs-context.js b/test/util/rs-context.js index 00869ffa..c42b6440 100644 --- a/test/util/rs-context.js +++ b/test/util/rs-context.js @@ -1,11 +1,11 @@ 'use strict' -var sinon = require('sinon') +const sinon = require('sinon') module.exports = function readStreamContext (t) { - var ctx = {} - var i - var k + const ctx = {} + let i + let k ctx.dataSpy = sinon.spy() ctx.endSpy = sinon.spy() @@ -27,7 +27,7 @@ module.exports = function readStreamContext (t) { t.is(ctx.dataSpy.callCount, data.length, 'ReadStream emitted correct number of "data" events') data.forEach(function (d, i) { - var call = ctx.dataSpy.getCall(i) + const call = ctx.dataSpy.getCall(i) if (call) { t.is(call.args.length, 1, 'ReadStream "data" event #' + i + ' fired with 1 argument') t.ok(call.args[0].key, 'ReadStream "data" event #' + i + ' argument has "key" property') diff --git a/test/util/rs-factory.js b/test/util/rs-factory.js index 0396da88..2cfa7dbf 100644 --- a/test/util/rs-factory.js +++ b/test/util/rs-factory.js @@ -1,6 +1,6 @@ 'use strict' -var xtend = require('xtend') +const xtend = require('xtend') module.exports = function (testCommon) { return function createReadStream (db, options) {