Wipe db before tests
This commit is contained in:
parent
9371f19419
commit
6259ffad3b
1 changed files with 25 additions and 11 deletions
|
@ -38,6 +38,8 @@ import { cleanup } from "../../utilities/fileSystem"
|
||||||
import newid from "../../db/newid"
|
import newid from "../../db/newid"
|
||||||
import { generateUserMetadataID } from "../../db/utils"
|
import { generateUserMetadataID } from "../../db/utils"
|
||||||
import { startup } from "../../startup"
|
import { startup } from "../../startup"
|
||||||
|
import { db } from "@budibase/backend-core"
|
||||||
|
import Nano from "@budibase/nano"
|
||||||
const supertest = require("supertest")
|
const supertest = require("supertest")
|
||||||
|
|
||||||
const GLOBAL_USER_ID = "us_uuid1"
|
const GLOBAL_USER_ID = "us_uuid1"
|
||||||
|
@ -127,6 +129,7 @@ class TestConfiguration {
|
||||||
|
|
||||||
// use a new id as the name to avoid name collisions
|
// use a new id as the name to avoid name collisions
|
||||||
async init(appName = newid()) {
|
async init(appName = newid()) {
|
||||||
|
await this.cleanAllDbs()
|
||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
await startup()
|
await startup()
|
||||||
}
|
}
|
||||||
|
@ -137,23 +140,34 @@ class TestConfiguration {
|
||||||
return this.createApp(appName)
|
return this.createApp(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
async end() {
|
async cleanAllDbs() {
|
||||||
|
const couchInfo = db.getCouchInfo()
|
||||||
|
const nano = Nano({
|
||||||
|
url: couchInfo.url,
|
||||||
|
requestDefaults: {
|
||||||
|
headers: {
|
||||||
|
Authorization: couchInfo.cookie,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
parseUrl: false,
|
||||||
|
})
|
||||||
|
let dbs
|
||||||
|
do {
|
||||||
|
dbs = await nano.db.list()
|
||||||
|
await Promise.all(dbs.map(x => nano.db.destroy(x)))
|
||||||
|
} while (dbs.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
end() {
|
||||||
if (!this) {
|
if (!this) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.allApps) {
|
|
||||||
cleanup(this.allApps.map(app => app.appId))
|
|
||||||
|
|
||||||
await this._req(
|
|
||||||
null,
|
|
||||||
{ appId: this.prodApp.appId },
|
|
||||||
controllers.app.destroy
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
this.server.close()
|
this.server.close()
|
||||||
}
|
}
|
||||||
|
if (this.allApps) {
|
||||||
|
cleanup(this.allApps.map(app => app.appId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTILS
|
// UTILS
|
||||||
|
|
Loading…
Reference in a new issue