Updating worker/server to run in cypress properly.

This commit is contained in:
mike12345567 2021-04-15 16:25:48 +01:00
parent 9af9761753
commit aacfb6adba
7 changed files with 166 additions and 5 deletions

View File

@ -3,13 +3,16 @@ const path = require("path")
const tmpdir = path.join(require("os").tmpdir(), ".budibase")
const WORKER_PORT = "4002"
const MAIN_PORT = cypressConfig.env.PORT
process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
process.env.NODE_ENV = "cypress"
process.env.ENABLE_ANALYTICS = "false"
process.env.PORT = cypressConfig.env.PORT
process.env.PORT = MAIN_PORT
process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET
process.env.COUCH_URL = `leveldb://${tmpdir}/.data/`
process.env.SELF_HOSTED = 1
process.env.WORKER_URL = "http://localhost:4002/"
process.env.MINIO_URL = "http://localhost:10000/"
process.env.MINIO_ACCESS_KEY = "budibase"
process.env.MINIO_SECRET_KEY = "budibase"
@ -25,7 +28,12 @@ async function run() {
// dont make this a variable or top level require
// it will cause environment module to be loaded prematurely
const server = require("../../server/src/app")
process.env.PORT = WORKER_PORT
const worker = require("../../worker/src/index")
// reload main port for rest of system
process.env.PORT = MAIN_PORT
server.on("close", () => console.log("Server Closed"))
worker.on("close", () => console.log("Worker Closed"))
}
run()

View File

@ -71,6 +71,9 @@ exports.authenticate = async ctx => {
}
exports.fetchSelf = async ctx => {
if (!ctx.user) {
ctx.throw(403, "No user logged in")
}
const appId = ctx.appId
const { userId } = ctx.user
/* istanbul ignore next */

View File

@ -4,7 +4,7 @@ const env = require("../../environment")
const router = Router()
if (env.isDev()) {
if (env.isDev() || env.isTest()) {
router.get("/api/admin/:path", controller.redirectGet)
router.post("/api/admin/:path", controller.redirectPost)
router.delete("/api/admin/:path", controller.redirectDelete)

View File

@ -44,6 +44,7 @@
"server-destroy": "^1.0.1"
},
"devDependencies": {
"nodemon": "^2.0.7"
"nodemon": "^2.0.7",
"pouchdb-adapter-memory": "^7.2.2"
}
}

View File

@ -7,8 +7,17 @@ const COUCH_DB_URL = env.COUCH_DB_URL || "http://localhost:10000/db/"
const Pouch = PouchDB.defaults({
prefix: COUCH_DB_URL,
skip_setup: env.isProd(),
})
if (env.isTest()) {
PouchDB.plugin(require("pouchdb-adapter-memory"))
POUCH_DB_DEFAULTS = {
prefix: undefined,
adapter: "memory",
}
}
allDbs(Pouch)
module.exports = Pouch

View File

@ -2,6 +2,14 @@ function isDev() {
return process.env.NODE_ENV !== "production"
}
function isTest() {
return (
process.env.NODE_ENV === "jest" ||
process.env.NODE_ENV === "cypress" ||
process.env.JEST_WORKER_ID != null
)
}
let LOADED = false
if (!LOADED && isDev()) {
require("dotenv").config()
@ -27,4 +35,8 @@ module.exports = {
module.exports[key] = value
},
isDev,
isTest,
isProd: () => {
return !isDev()
},
}

View File

@ -142,6 +142,13 @@ abstract-leveldown@^6.2.1:
level-supports "~1.0.0"
xtend "~4.0.0"
abstract-leveldown@~2.7.1:
version "2.7.2"
resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-2.7.2.tgz#87a44d7ebebc341d59665204834c8b7e0932cc93"
integrity sha512-+OVvxH2rHVEhWLdbudP6p0+dNMXu8JA1CbhP19T8paTYAcX7oJ4OVjT+ZUVpv7mITxXHqDMej+GdqXBmXkw09w==
dependencies:
xtend "~4.0.0"
abstract-leveldown@~6.2.1, abstract-leveldown@~6.2.3:
version "6.2.3"
resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz#036543d87e3710f2528e47040bc3261b77a9a8eb"
@ -919,6 +926,11 @@ fsevents@~2.3.1:
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
functional-red-black-tree@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
get-stream@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
@ -1632,7 +1644,7 @@ lowercase-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479"
integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==
ltgt@2.2.1, ltgt@^2.1.2:
ltgt@2.2.1, ltgt@^2.1.2, ltgt@~2.2.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5"
integrity sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=
@ -1649,6 +1661,18 @@ media-typer@0.3.0:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
memdown@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/memdown/-/memdown-1.4.1.tgz#b4e4e192174664ffbae41361aa500f3119efe215"
integrity sha1-tOThkhdGZP+65BNhqlAPMRnv4hU=
dependencies:
abstract-leveldown "~2.7.1"
functional-red-black-tree "^1.0.1"
immediate "^3.2.3"
inherits "~2.0.1"
ltgt "~2.2.0"
safe-buffer "~5.1.1"
methods@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
@ -1972,6 +1996,47 @@ pino@^6.0.0:
quick-format-unescaped "^4.0.1"
sonic-boom "^1.0.2"
pouchdb-adapter-leveldb-core@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-adapter-leveldb-core/-/pouchdb-adapter-leveldb-core-7.2.2.tgz#e0aa6a476e2607d7ae89f4a803c9fba6e6d05a8a"
integrity sha512-K9UGf1Ivwe87mjrMqN+1D07tO/DfU7ariVDrGffuOjvl+3BcvUF25IWrxsBObd4iPOYCH7NVQWRpojhBgxULtQ==
dependencies:
argsarray "0.0.1"
buffer-from "1.1.1"
double-ended-queue "2.1.0-0"
levelup "4.4.0"
pouchdb-adapter-utils "7.2.2"
pouchdb-binary-utils "7.2.2"
pouchdb-collections "7.2.2"
pouchdb-errors "7.2.2"
pouchdb-json "7.2.2"
pouchdb-md5 "7.2.2"
pouchdb-merge "7.2.2"
pouchdb-utils "7.2.2"
sublevel-pouchdb "7.2.2"
through2 "3.0.2"
pouchdb-adapter-memory@^7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-adapter-memory/-/pouchdb-adapter-memory-7.2.2.tgz#c0ec2e87928d516ca9d1b5badc7269df6f95e5ea"
integrity sha512-9o+zdItPEq7rIrxdkUxgsLNaZkDJAGEqqoYgeYdrHidOCZnlhxhX3g7/R/HcpDKC513iEPqJWDJQSfeT6nVKkw==
dependencies:
memdown "1.4.1"
pouchdb-adapter-leveldb-core "7.2.2"
pouchdb-utils "7.2.2"
pouchdb-adapter-utils@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-adapter-utils/-/pouchdb-adapter-utils-7.2.2.tgz#c64426447d9044ba31517a18500d6d2d28abd47d"
integrity sha512-2CzZkTyTyHZkr3ePiWFMTiD5+56lnembMjaTl8ohwegM0+hYhRyJux0biAZafVxgIL4gnCUC4w2xf6WVztzKdg==
dependencies:
pouchdb-binary-utils "7.2.2"
pouchdb-collections "7.2.2"
pouchdb-errors "7.2.2"
pouchdb-md5 "7.2.2"
pouchdb-merge "7.2.2"
pouchdb-utils "7.2.2"
pouchdb-all-dbs@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pouchdb-all-dbs/-/pouchdb-all-dbs-1.0.2.tgz#8fa1aa4b01665e00e0da9c61bf6dbb99eca05d3c"
@ -1983,6 +2048,45 @@ pouchdb-all-dbs@^1.0.2:
pouchdb-promise "5.4.3"
tiny-queue "^0.2.0"
pouchdb-binary-utils@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-binary-utils/-/pouchdb-binary-utils-7.2.2.tgz#0690b348052c543b1e67f032f47092ca82bcb10e"
integrity sha512-shacxlmyHbUrNfE6FGYpfyAJx7Q0m91lDdEAaPoKZM3SzAmbtB1i+OaDNtYFztXjJl16yeudkDb3xOeokVL3Qw==
dependencies:
buffer-from "1.1.1"
pouchdb-collections@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-collections/-/pouchdb-collections-7.2.2.tgz#aeed77f33322429e3f59d59ea233b48ff0e68572"
integrity sha512-6O9zyAYlp3UdtfneiMYuOCWdUCQNo2bgdjvNsMSacQX+3g8WvIoFQCYJjZZCpTttQGb+MHeRMr8m2U95lhJTew==
pouchdb-errors@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-errors/-/pouchdb-errors-7.2.2.tgz#80d811d65c766c9d20b755c6e6cc123f8c3c4792"
integrity sha512-6GQsiWc+7uPfgEHeavG+7wuzH3JZW29Dnrvz8eVbDFE50kVFxNDVm3EkYHskvo5isG7/IkOx7PV7RPTA3keG3g==
dependencies:
inherits "2.0.4"
pouchdb-json@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-json/-/pouchdb-json-7.2.2.tgz#b939be24b91a7322e9a24b8880a6e21514ec5e1f"
integrity sha512-3b2S2ynN+aoB7aCNyDZc/4c0IAdx/ir3nsHB+/RrKE9cM3QkQYbnnE3r/RvOD1Xvr6ji/KOCBie+Pz/6sxoaug==
dependencies:
vuvuzela "1.0.3"
pouchdb-md5@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-md5/-/pouchdb-md5-7.2.2.tgz#415401acc5a844112d765bd1fb4e5d9f38fb0838"
integrity sha512-c/RvLp2oSh8PLAWU5vFBnp6ejJABIdKqboZwRRUrWcfGDf+oyX8RgmJFlYlzMMOh4XQLUT1IoaDV8cwlsuryZw==
dependencies:
pouchdb-binary-utils "7.2.2"
spark-md5 "3.0.1"
pouchdb-merge@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-merge/-/pouchdb-merge-7.2.2.tgz#940d85a2b532d6a93a6cab4b250f5648511bcc16"
integrity sha512-6yzKJfjIchBaS7Tusuk8280WJdESzFfQ0sb4jeMUNnrqs4Cx3b0DIEOYTRRD9EJDM+je7D3AZZ4AT0tFw8gb4A==
pouchdb-promise@5.4.3:
version "5.4.3"
resolved "https://registry.yarnpkg.com/pouchdb-promise/-/pouchdb-promise-5.4.3.tgz#331d670b1989d5a03f268811214f27f54150cb2b"
@ -1990,6 +2094,20 @@ pouchdb-promise@5.4.3:
dependencies:
lie "3.0.4"
pouchdb-utils@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb-utils/-/pouchdb-utils-7.2.2.tgz#c17c4788f1d052b0daf4ef8797bbc4aaa3945aa4"
integrity sha512-XmeM5ioB4KCfyB2MGZXu1Bb2xkElNwF1qG+zVFbQsKQij0zvepdOUfGuWvLRHxTOmt4muIuSOmWZObZa3NOgzQ==
dependencies:
argsarray "0.0.1"
clone-buffer "1.0.0"
immediate "3.3.0"
inherits "2.0.4"
pouchdb-collections "7.2.2"
pouchdb-errors "7.2.2"
pouchdb-md5 "7.2.2"
uuid "8.1.0"
pouchdb@^7.2.1:
version "7.2.2"
resolved "https://registry.yarnpkg.com/pouchdb/-/pouchdb-7.2.2.tgz#fcae82862db527e4cf7576ed8549d1384961f364"
@ -2218,7 +2336,7 @@ responselike@^2.0.0:
dependencies:
lowercase-keys "^2.0.0"
safe-buffer@5.1.2:
safe-buffer@5.1.2, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
@ -2388,6 +2506,16 @@ strip-json-comments@~2.0.1:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
sublevel-pouchdb@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/sublevel-pouchdb/-/sublevel-pouchdb-7.2.2.tgz#49e46cd37883bf7ff5006d7c5b9bcc7bcc1f422f"
integrity sha512-y5uYgwKDgXVyPZceTDGWsSFAhpSddY29l9PJbXqMJLfREdPmQTY8InpatohlEfCXX7s1LGcrfYAhxPFZaJOLnQ==
dependencies:
inherits "2.0.4"
level-codec "9.0.2"
ltgt "2.2.1"
readable-stream "1.1.14"
supports-color@^5.3.0, supports-color@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"