Skip to content

Commit

Permalink
ci: make ci pass by stop requiring leveldown while run test
Browse files Browse the repository at this point in the history
  • Loading branch information
terrencewwong committed Mar 23, 2017
1 parent 9df792f commit 35fdfde
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/level-db-wrapper/level-db-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* @flow */
const levelup = require('levelup')
const leveldown = require('leveldown')
const memdown = require('memdown')
const promisify = require('q-level')

type ConstructorOptions = {
Expand All @@ -10,12 +8,13 @@ type ConstructorOptions = {

type DBConfig = {
valueEncoding: string,
db?: Object
db: Object
}

class LevelDBWrapper {
location: string;
adapter: ?string;
dbConfig: DBConfig;
db: Object;

constructor (location: string, options?: ConstructorOptions = {}) {
Expand All @@ -26,12 +25,14 @@ class LevelDBWrapper {
this.location = location
this.adapter = options.adapter

const dbConfig: DBConfig = {valueEncoding: 'json'}
if (this.adapter === 'memory') {
dbConfig.db = memdown
this.dbConfig = {
valueEncoding: 'json',
db: this.adapter === 'memory'
? require('memdown')
: require('leveldown')
}

this.db = promisify(levelup(this.location, dbConfig))
this.db = promisify(levelup(this.location, this.dbConfig))
}

async get (key: string): Promise<any> {
Expand All @@ -44,11 +45,11 @@ class LevelDBWrapper {

async destroy (): Promise<any> {
if (this.adapter === 'memory') {
return memdown.clearGlobalStore(true)
return this.dbConfig.db.clearGlobalStore(true)
}

return new Promise((resolve, reject) => {
leveldown.destroy(this.location, err => {
this.dbConfig.db.destroy(this.location, err => {
if (err) reject(err)
resolve()
})
Expand Down

0 comments on commit 35fdfde

Please sign in to comment.