From eae5d4dc4dc5d019065b0cacb0136bc21d1ed88f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 20 May 2022 18:29:37 +0100 Subject: [PATCH] Removing the use of pouchdb-all-dbs from testing environment, it was causing more harm than good and was entirely avoidable. --- packages/backend-core/package.json | 3 +-- packages/backend-core/src/db/index.js | 12 +++++++++--- packages/backend-core/src/db/pouch.js | 8 +------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index c0265f110a..bbd7a1af6b 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -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" } diff --git a/packages/backend-core/src/db/index.js b/packages/backend-core/src/db/index.js index 7d54b881b1..d179186988 100644 --- a/packages/backend-core/src/db/index.js +++ b/packages/backend-core/src/db/index.js @@ -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] } diff --git a/packages/backend-core/src/db/pouch.js b/packages/backend-core/src/db/pouch.js index 9c1ada8d76..76390ac644 100644 --- a/packages/backend-core/src/db/pouch.js +++ b/packages/backend-core/src/db/pouch.js @@ -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) }