Removing the use of pouchdb-all-dbs from testing environment, it was causing more harm than good and was entirely avoidable.

This commit is contained in:
mike12345567 2022-05-20 18:29:37 +01:00
parent 5b1ae1f6fc
commit eae5d4dc4d
3 changed files with 11 additions and 12 deletions

View File

@ -41,8 +41,7 @@
"devDependencies": {
"ioredis-mock": "^5.5.5",
"jest": "^26.6.3",
"pouchdb-adapter-memory": "^7.2.2",
"pouchdb-all-dbs": "^1.0.2"
"pouchdb-adapter-memory": "^7.2.2"
},
"gitHead": "d1836a898cab3f8ab80ee6d8f42be1a9eed7dcdc"
}

View File

@ -3,13 +3,13 @@ const env = require("../environment")
let PouchDB
let initialised = false
const dbList = new Set()
const put =
dbPut =>
async (doc, options = {}) => {
const response = await dbPut(doc, options)
// TODO: add created / updated
return response
return await dbPut(doc, options)
}
const checkInitialised = () => {
@ -28,6 +28,9 @@ exports.init = opts => {
// in situations that using the function doWithDB does not work
exports.dangerousGetDB = (dbName, opts) => {
checkInitialised()
if (env.isTest()) {
dbList.add(dbName)
}
const db = new PouchDB(dbName, opts)
const dbPut = db.put
db.put = put(dbPut)
@ -63,6 +66,9 @@ exports.doWithDB = async (dbName, cb, opts) => {
}
exports.allDbs = () => {
if (!env.isTest()) {
throw new Error("Cannot be used outside test environment.")
}
checkInitialised()
return PouchDB.allDbs()
return [...dbList]
}

View File

@ -92,11 +92,5 @@ exports.getPouch = (opts = {}) => {
PouchDB.plugin(find)
}
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
if (opts.allDbs) {
const allDbs = require("pouchdb-all-dbs")
allDbs(Pouch)
}
return Pouch
return PouchDB.defaults(POUCH_DB_DEFAULTS)
}