Changing how we enforce backend JS.

This commit is contained in:
mike12345567 2025-01-20 17:02:57 +00:00
parent 68374bce29
commit 04a7878ce9
5 changed files with 8 additions and 9 deletions

View File

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

View File

@ -43,6 +43,7 @@ import {
import TestConfiguration from "../../../tests/utilities/TestConfiguration" import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import * as setup from "../utilities" import * as setup from "../utilities"
import { automations } from "@budibase/shared-core" import { automations } from "@budibase/shared-core"
import { setTestingBackendJS } from "@budibase/string-templates"
type TriggerOutputs = type TriggerOutputs =
| RowCreatedTriggerOutputs | RowCreatedTriggerOutputs

View File

@ -4,12 +4,17 @@ import {
JsTimeoutError, JsTimeoutError,
setJSRunner, setJSRunner,
setOnErrorLog, setOnErrorLog,
setTestingBackendJS,
} from "@budibase/string-templates" } from "@budibase/string-templates"
import { context, logging } from "@budibase/backend-core" import { context, logging } from "@budibase/backend-core"
import tracer from "dd-trace" import tracer from "dd-trace"
import { IsolatedVM } from "./vm" import { IsolatedVM } from "./vm"
export function init() { export function init() {
// enforce that if we're using isolated-VM runner then we are running backend JS
if (env.isTest()) {
setTestingBackendJS()
}
setJSRunner((js: string, ctx: Record<string, any>) => { setJSRunner((js: string, ctx: Record<string, any>) => {
return tracer.trace("runJS", {}, () => { return tracer.trace("runJS", {}, () => {
try { try {

View File

@ -1,9 +1,5 @@
import { validate as isValidUUID } from "uuid" import { validate as isValidUUID } from "uuid"
import { import { processStringSync, encodeJSBinding } from "@budibase/string-templates"
processStringSync,
encodeJSBinding,
setTestingBackendJS,
} from "@budibase/string-templates"
import { runJsHelpersTests } from "@budibase/string-templates/test/utils" import { runJsHelpersTests } from "@budibase/string-templates/test/utils"
@ -11,7 +7,6 @@ import tk from "timekeeper"
import { init } from ".." import { init } from ".."
import TestConfiguration from "../../tests/utilities/TestConfiguration" import TestConfiguration from "../../tests/utilities/TestConfiguration"
setTestingBackendJS()
const DATE = "2021-01-21T12:00:00" const DATE = "2021-01-21T12:00:00"
tk.freeze(DATE) tk.freeze(DATE)

View File

@ -88,7 +88,7 @@ export function processJS(handlebars: string, context: any) {
let clonedContext: Record<string, any> let clonedContext: Record<string, any>
if (isBackendService()) { if (isBackendService()) {
// On the backned, values are copied across the isolated-vm boundary and // On the backend, values are copied across the isolated-vm boundary and
// so we don't need to do any cloning here. This does create a fundamental // so we don't need to do any cloning here. This does create a fundamental
// difference in how JS executes on the frontend vs the backend, e.g. // difference in how JS executes on the frontend vs the backend, e.g.
// consider this snippet: // consider this snippet: