Prevent local port conflicts between account portal and cypress

This commit is contained in:
Rory Powell 2022-02-22 11:20:58 +00:00
parent 5862fc2322
commit a1e2bd86c6
4 changed files with 27 additions and 19 deletions

View File

@ -1,9 +1,10 @@
{ {
"baseUrl": "http://localhost:10001/builder/", "baseUrl": "http://localhost:41000/builder/",
"video": true, "video": true,
"projectId": "bmbemn", "projectId": "bmbemn",
"env": { "env": {
"PORT": "10001", "PORT": "41000",
"WORKER_PORT": "42000",
"JWT_SECRET": "test" "JWT_SECRET": "test"
} }
} }

View File

@ -4,17 +4,17 @@ const path = require("path")
const tmpdir = path.join(require("os").tmpdir(), ".budibase") const tmpdir = path.join(require("os").tmpdir(), ".budibase")
// normal development system // normal development system
const WORKER_PORT = "10002" const SERVER_PORT = cypressConfig.env.PORT
const MAIN_PORT = cypressConfig.env.PORT const WORKER_PORT = cypressConfig.env.WORKER_PORT
process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE" process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
process.env.NODE_ENV = "cypress" process.env.NODE_ENV = "cypress"
process.env.ENABLE_ANALYTICS = "false" process.env.ENABLE_ANALYTICS = "false"
process.env.PORT = MAIN_PORT
process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET
process.env.COUCH_URL = `leveldb://${tmpdir}/.data/` process.env.COUCH_URL = `leveldb://${tmpdir}/.data/`
process.env.SELF_HOSTED = 1 process.env.SELF_HOSTED = 1
process.env.WORKER_URL = "http://localhost:10002/" process.env.WORKER_URL = `http://localhost:${WORKER_PORT}/`
process.env.APPS_URL = `http://localhost:${MAIN_PORT}/` process.env.APPS_URL = `http://localhost:${SERVER_PORT}/`
process.env.MINIO_URL = `http://localhost:4004` process.env.MINIO_URL = `http://localhost:4004`
process.env.MINIO_ACCESS_KEY = "budibase" process.env.MINIO_ACCESS_KEY = "budibase"
process.env.MINIO_SECRET_KEY = "budibase" process.env.MINIO_SECRET_KEY = "budibase"
@ -33,11 +33,14 @@ exports.run = (
// require("dotenv").config({ path: resolve(dir, ".env") }) // require("dotenv").config({ path: resolve(dir, ".env") })
// don't make this a variable or top level require // don't make this a variable or top level require
// it will cause environment module to be loaded prematurely // it will cause environment module to be loaded prematurely
require(serverLoc)
// override the port with the worker port temporarily
process.env.PORT = WORKER_PORT process.env.PORT = WORKER_PORT
require(workerLoc) require(workerLoc)
// reload main port for rest of system
process.env.PORT = MAIN_PORT // override the port with the server port
process.env.PORT = SERVER_PORT
require(serverLoc)
} }
if (require.main === module) { if (require.main === module) {

View File

@ -14,9 +14,10 @@
"cy:run": "cypress run", "cy:run": "cypress run",
"cy:open": "cypress open", "cy:open": "cypress open",
"cy:run:ci": "cypress run --record", "cy:run:ci": "cypress run --record",
"cy:test": "start-server-and-test cy:setup http://localhost:10001/builder cy:run", "cy:test": "start-server-and-test cy:setup http://localhost:41000/builder cy:run",
"cy:ci": "start-server-and-test cy:setup:ci http://localhost:10001/builder cy:run", "cy:ci": "start-server-and-test cy:setup:ci http://localhost:41000/builder cy:run",
"cy:debug": "start-server-and-test cy:setup http://localhost:10001/builder cy:open" "cy:debug": "start-server-and-test cy:setup http://localhost:41000/builder cy:open",
"cy:debug:ci": "start-server-and-test cy:setup:ci http://localhost:41000/builder cy:open"
}, },
"jest": { "jest": {
"globals": { "globals": {

View File

@ -2,14 +2,13 @@
* This script just makes it easy to re-create * * This script just makes it easy to re-create *
* a cypress like environment for testing the backend * * a cypress like environment for testing the backend *
******************************************************/ ******************************************************/
const path = require("path") import path from "path"
const tmpdir = path.join(require("os").tmpdir(), ".budibase") const tmpdir = path.join(require("os").tmpdir(), ".budibase")
const MAIN_PORT = "10001" const SERVER_PORT = "41000"
const WORKER_PORT = "10002" const WORKER_PORT = "42000"
// @ts-ignore // @ts-ignore
process.env.PORT = MAIN_PORT
process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE" process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
process.env.NODE_ENV = "cypress" process.env.NODE_ENV = "cypress"
process.env.ENABLE_ANALYTICS = "false" process.env.ENABLE_ANALYTICS = "false"
@ -27,7 +26,11 @@ process.env.ALLOW_DEV_AUTOMATIONS = "1"
// don't make this a variable or top level require // don't make this a variable or top level require
// it will cause environment module to be loaded prematurely // it will cause environment module to be loaded prematurely
const server = require("../src/app")
// override the port with the worker port temporarily
process.env.PORT = WORKER_PORT process.env.PORT = WORKER_PORT
const worker = require("../../worker/src/index") const worker = require("../../worker/src/index")
process.env.PORT = MAIN_PORT
// override the port with the server port
process.env.PORT = SERVER_PORT
const server = require("../src/app")