Adding the ability to configure whether or not string templates is testing backend JS or frontend.

This commit is contained in:
mike12345567 2025-01-20 16:33:21 +00:00
parent 9c65f1ab41
commit 98bd824d7a
4 changed files with 23 additions and 3 deletions

View File

@ -50,9 +50,11 @@ import { JsTimeoutError } from "@budibase/string-templates"
import { isDate } from "../../../utilities"
import nock from "nock"
import { mockChatGPTResponse } from "../../../tests/utilities/mocks/openai"
import { setTestingBackendJS } from "@budibase/string-templates"
const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString()
tk.freeze(timestamp)
setTestingBackendJS()
interface WaitOptions {
name: string
matchFn?: (event: any) => boolean

View File

@ -9,3 +9,15 @@ function isJest() {
export function isTest() {
return isJest()
}
export const isJSAllowed = () => {
return process && !process.env.NO_JS
}
export const isTestingBackendJS = () => {
return process && process.env.BACKEND_JS
}
export const setTestingBackendJS = () => {
process.env.BACKEND_JS = "1"
}

View File

@ -20,6 +20,7 @@ import { Log, ProcessOptions } from "./types"
import { UserScriptError } from "./errors"
export type { Log, LogType } from "./types"
export { setTestingBackendJS } from "./environment"
export { helpersToRemoveForJs, getJsHelperList } from "./helpers/list"
export { FIND_ANY_HBS_REGEX } from "./utilities"
export { setJSRunner, setOnErrorLog } from "./helpers/javascript"

View File

@ -1,15 +1,20 @@
import { isTest, isTestingBackendJS } from "./environment"
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
export const FIND_HBS_REGEX = /{{([^{].*?)}}/g
export const FIND_ANY_HBS_REGEX = /{?{{([^{].*?)}}}?/g
export const FIND_TRIPLE_HBS_REGEX = /{{{([^{].*?)}}}/g
const isJest = () => typeof jest !== "undefined"
export const isBackendService = () => {
// allow configuring backend JS mode when testing - we default to assuming
// frontend, but need a method to control this
if (isTest() && isTestingBackendJS()) {
return true
}
// We consider the tests for string-templates to be frontend, so that they
// test the frontend JS functionality.
if (isJest()) {
if (isTest()) {
return false
}
return typeof window === "undefined"