diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json new file mode 100644 index 0000000000..68117490f4 --- /dev/null +++ b/packages/builder/cypress.json @@ -0,0 +1,15 @@ +{ + "baseUrl": "http://localhost:4100", + "video": true, + "projectId": "bmbemn", + "reporter": "cypress-multi-reporters", + "reporterOptions": { + "configFile": "reporterConfig.json" + }, + "env": { + "PORT": "4100", + "WORKER_PORT": "4200", + "JWT_SECRET": "test", + "HOST_IP": "" + } +} \ No newline at end of file diff --git a/packages/builder/setup.js b/packages/builder/setup.js new file mode 100644 index 0000000000..eaadb64d39 --- /dev/null +++ b/packages/builder/setup.js @@ -0,0 +1,42 @@ +const cypressConfig = require("./cypress.json") + +// normal development system +const SERVER_PORT = cypressConfig.env.PORT +const WORKER_PORT = cypressConfig.env.WORKER_PORT + +if (!process.env.NODE_ENV) { + process.env.NODE_ENV = "cypress" +} +process.env.ENABLE_ANALYTICS = "0" +process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET +process.env.SELF_HOSTED = 1 +process.env.WORKER_URL = `http://localhost:${WORKER_PORT}/` +process.env.APPS_URL = `http://localhost:${SERVER_PORT}/` +process.env.MINIO_URL = `http://localhost:4004` +process.env.MINIO_ACCESS_KEY = "budibase" +process.env.MINIO_SECRET_KEY = "budibase" +process.env.COUCH_DB_USER = "budibase" +process.env.COUCH_DB_PASSWORD = "budibase" +process.env.INTERNAL_API_KEY = "budibase" +process.env.ALLOW_DEV_AUTOMATIONS = 1 + +// Stop info logs polluting test outputs +process.env.LOG_LEVEL = "error" + +exports.run = (serverLoc = "../server/dist", workerLoc = "../worker/dist") => { + // require("dotenv").config({ path: resolve(dir, ".env") }) + // don't make this a variable or top level require + // it will cause environment module to be loaded prematurely + + // override the port with the worker port temporarily + process.env.PORT = WORKER_PORT + require(workerLoc) + + // override the port with the server port + process.env.PORT = SERVER_PORT + require(serverLoc) +} + +if (require.main === module) { + exports.run() +} diff --git a/packages/builder/ts/setup.ts b/packages/builder/ts/setup.ts new file mode 100644 index 0000000000..12965ce7c9 --- /dev/null +++ b/packages/builder/ts/setup.ts @@ -0,0 +1,4 @@ +// @ts-ignore +import { run } from "../setup" + +run("../server/src/index", "../worker/src/index") diff --git a/qa-core/package.json b/qa-core/package.json index bf760c17a3..8508361566 100644 --- a/qa-core/package.json +++ b/qa-core/package.json @@ -14,8 +14,8 @@ "test:debug": "DEBUG=1 jest", "docker:up": "docker-compose up -d", "docker:down": "docker-compose down", - "api:server:setup": "npm run docker:up && env-cmd ts-node ../packages/builder/cypress/ts/setup.ts", - "api:server:setup:ci": "env-cmd node ../packages/builder/cypress/setup.js", + "api:server:setup": "npm run docker:up && env-cmd ts-node ../packages/builder/ts/setup.ts", + "api:server:setup:ci": "env-cmd node ../packages/builder/setup.js", "api:test:ci": "start-server-and-test api:server:setup:ci http://localhost:4100/builder test", "api:test": "start-server-and-test api:server:setup http://localhost:4100/builder test" },