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 f0211a0ce8
commit 1b86041c68
3 changed files with 11 additions and 12 deletions

View File

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

View File

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

View File

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