Clean cypress refs

This commit is contained in:
Adria Navarro 2023-09-07 15:37:22 +02:00
parent 0f9552560b
commit 205d33f172
6 changed files with 20 additions and 58 deletions

View File

@ -55,7 +55,7 @@ export async function getAppMetadata(appId: string): Promise<App | DeletedApp> {
throw err throw err
} }
} }
// needed for cypress/some scenarios where the caching happens // needed for some scenarios where the caching happens
// so quickly the requests can get slightly out of sync // so quickly the requests can get slightly out of sync
// might store its invalid just before it stores its valid // might store its invalid just before it stores its valid
if (isInvalid(metadata)) { if (isInvalid(metadata)) {

View File

@ -2,15 +2,15 @@ import { existsSync, readFileSync } from "fs"
import { ServiceType } from "@budibase/types" import { ServiceType } from "@budibase/types"
function isTest() { function isTest() {
return isCypress() || isJest() return isJest()
} }
function isJest() { function isJest() {
return !!(process.env.NODE_ENV === "jest" || process.env.JEST_WORKER_ID) return (
} process.env.NODE_ENV === "jest" ||
(process.env.JEST_WORKER_ID != null &&
function isCypress() { process.env.JEST_WORKER_ID !== "null")
return process.env.NODE_ENV === "cypress" )
} }
function isDev() { function isDev() {

View File

@ -3,28 +3,8 @@ import { ServiceType } from "@budibase/types"
coreEnv._set("SERVICE_TYPE", ServiceType.APPS) coreEnv._set("SERVICE_TYPE", ServiceType.APPS)
import { join } from "path" import { join } from "path"
function isTest() {
return isCypress() || isJest()
}
function isJest() {
return (
process.env.NODE_ENV === "jest" ||
(process.env.JEST_WORKER_ID != null &&
process.env.JEST_WORKER_ID !== "null")
)
}
function isDev() {
return process.env.NODE_ENV !== "production"
}
function isCypress() {
return process.env.NODE_ENV === "cypress"
}
let LOADED = false let LOADED = false
if (!LOADED && isDev() && !isTest()) { if (!LOADED && coreEnv.isDev() && !coreEnv.isTest()) {
require("dotenv").config({ require("dotenv").config({
path: join(__dirname, "..", ".env"), path: join(__dirname, "..", ".env"),
}) })
@ -93,12 +73,12 @@ const environment = {
// @ts-ignore // @ts-ignore
environment[key] = value environment[key] = value
}, },
isTest, isTest: coreEnv.isTest,
isJest, isJest: coreEnv.isJest,
isCypress,
isDev, isDev: coreEnv.isDev,
isProd: () => { isProd: () => {
return !isDev() return !coreEnv.isDev()
}, },
isInThread: () => { isInThread: () => {
return process.env.FORKED_PROCESS return process.env.FORKED_PROCESS
@ -108,7 +88,7 @@ const environment = {
} }
// threading can cause memory issues with node-ts in development // threading can cause memory issues with node-ts in development
if (isDev() && environment.DISABLE_THREADING == null) { if (coreEnv.isDev() && environment.DISABLE_THREADING == null) {
environment._set("DISABLE_THREADING", "1") environment._set("DISABLE_THREADING", "1")
} }

View File

@ -34,11 +34,6 @@ import pick from "lodash/pick"
export async function search(options: SearchParams) { export async function search(options: SearchParams) {
const { tableId } = options const { tableId } = options
// Fetch the whole table when running in cypress, as search doesn't work
if (!env.COUCH_DB_URL && env.isCypress()) {
return { rows: await fetch(tableId) }
}
const { paginate, query } = options const { paginate, query } = options
const params: InternalSearchParams<any> = { const params: InternalSearchParams<any> = {

View File

@ -10,7 +10,6 @@ export const fetch = async (ctx: Ctx) => {
accountPortalUrl: env.ACCOUNT_PORTAL_URL, accountPortalUrl: env.ACCOUNT_PORTAL_URL,
disableAccountPortal: env.DISABLE_ACCOUNT_PORTAL, disableAccountPortal: env.DISABLE_ACCOUNT_PORTAL,
baseUrl: env.PLATFORM_URL, baseUrl: env.PLATFORM_URL,
// in test need to pretend its in production for the UI (Cypress) isDev: env.isDev(),
isDev: env.isDev() && !env.isTest(),
} }
} }

View File

@ -4,20 +4,8 @@ import { join } from "path"
coreEnv._set("SERVICE_TYPE", ServiceType.WORKER) coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
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 let LOADED = false
if (!LOADED && isDev() && !isTest()) { if (!LOADED && coreEnv.isDev() && !coreEnv.isTest()) {
require("dotenv").config({ require("dotenv").config({
path: join(__dirname, "..", ".env"), path: join(__dirname, "..", ".env"),
}) })
@ -85,16 +73,16 @@ const environment = {
// @ts-ignore // @ts-ignore
environment[key] = value environment[key] = value
}, },
isDev, isDev: coreEnv.isDev,
isTest, isTest: coreEnv.isTest,
isProd: () => { isProd: () => {
return !isDev() return !coreEnv.isDev()
}, },
} }
// if some var haven't been set, define them // if some var haven't been set, define them
if (!environment.APPS_URL) { if (!environment.APPS_URL) {
environment.APPS_URL = isDev() environment.APPS_URL = coreEnv.isDev()
? "http://localhost:4001" ? "http://localhost:4001"
: "http://app-service:4002" : "http://app-service:4002"
} }