Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Remove levelup from destroy tests #136

Merged
merged 1 commit into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
"devDependencies": {
"airtap": "0.0.7",
"buffer": "~5.1.0",
"levelup": "~3.0.0",
"pinkie": "~2.0.4",
"standard": "^11.0.1",
"tape": "^4.0.0"
},
Expand Down
60 changes: 35 additions & 25 deletions test/custom-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

var levelup = require('levelup')

module.exports = function (leveljs, test, testCommon) {
test('setUp', testCommon.setUp)

Expand Down Expand Up @@ -165,46 +163,58 @@ module.exports = function (leveljs, test, testCommon) {
// NOTE: in chrome (at least) indexeddb gets buggy if you try and destroy a db,
// then create it again, then try and destroy it again. these avoid doing that

test('test levelup .destroy', function (t) {
test('test .destroy', function (t) {
var location = testCommon.location()
var db = levelup(leveljs(location))
db.put('key', 'value', function (err) {
var db = leveljs(location)
db.open(function (err) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to rewrite tests a bit since levelup takes care of db.open().

t.notOk(err, 'no error')
db.get('key', { asBuffer: false }, function (err, value) {
db.put('key', 'value', function (err) {
t.notOk(err, 'no error')
t.equal(value, 'value', 'should have value')
db.close(function (err) {
db.get('key', { asBuffer: false }, function (err, value) {
t.notOk(err, 'no error')
leveljs.destroy(location, function (err) {
t.equal(value, 'value', 'should have value')
db.close(function (err) {
t.notOk(err, 'no error')
var db2 = levelup(leveljs(location))
db2.get('key', { asBuffer: false }, function (err, value) {
t.ok(err && err.notFound, 'key is not there')
db2.close(t.end.bind(t))
leveljs.destroy(location, function (err) {
t.notOk(err, 'no error')
var db2 = leveljs(location)
db2.open(function (err) {
t.notOk(err, 'no error')
db2.get('key', { asBuffer: false }, function (err, value) {
t.is(err.message, 'NotFound', 'key is not there')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is different since err.notFound is true due to levelup.

db2.close(t.end.bind(t))
})
})
})
})
})
})
})
})

test('test levelup .destroy and custom prefix', function (t) {
test('test .destroy and custom prefix', function (t) {
var location = testCommon.location()
var prefix = 'CUSTOM-PREFIX-'
var db = levelup(leveljs(location, { prefix: prefix }))
db.put('key', 'value', function (err) {
var prefix = 'custom-'
var db = leveljs(location, { prefix: prefix })
db.open(function (err) {
t.notOk(err, 'no error')
db.get('key', { asBuffer: false }, function (err, value) {
db.put('key', 'value', function (err) {
t.notOk(err, 'no error')
t.equal(value, 'value', 'should have value')
db.close(function (err) {
db.get('key', { asBuffer: false }, function (err, value) {
t.notOk(err, 'no error')
leveljs.destroy(location, prefix, function (err) {
t.equal(value, 'value', 'should have value')
db.close(function (err) {
t.notOk(err, 'no error')
var db2 = levelup(leveljs(location, { prefix: prefix }))
db2.get('key', { asBuffer: false }, function (err, value) {
t.ok(err && err.notFound, 'key is not there')
db2.close(t.end.bind(t))
leveljs.destroy(location, prefix, function (err) {
t.notOk(err, 'no error')
var db2 = leveljs(location, { prefix: prefix })
db2.open(function (err) {
t.notOk(err, 'no error')
db2.get('key', { asBuffer: false }, function (err, value) {
t.is(err.message, 'NotFound', 'key is not there')
db2.close(t.end.bind(t))
})
})
})
})
})
Expand Down
5 changes: 0 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict'

// Promise polyfill for IE and others.
if (process.browser && typeof Promise !== 'function') {
global.Promise = require('pinkie')
}

// Load IndexedDBShim
// require('./util/idb-shim.js')()

Expand Down