Using node vm for string-template test cases.
This commit is contained in:
parent
a3605922ee
commit
afb9f86bf7
|
@ -1,4 +1,5 @@
|
||||||
import vm from "@budibase/vm-browserify"
|
import browserVM from "@budibase/vm-browserify"
|
||||||
|
import vm from "vm"
|
||||||
import { create, TemplateDelegate } from "handlebars"
|
import { create, TemplateDelegate } from "handlebars"
|
||||||
import { registerAll, registerMinimum } from "./helpers/index"
|
import { registerAll, registerMinimum } from "./helpers/index"
|
||||||
import { postprocess, postprocessWithLogs, preprocess } from "./processors"
|
import { postprocess, postprocessWithLogs, preprocess } from "./processors"
|
||||||
|
@ -14,10 +15,10 @@ import {
|
||||||
} from "./utilities"
|
} from "./utilities"
|
||||||
import { convertHBSBlock } from "./conversion"
|
import { convertHBSBlock } from "./conversion"
|
||||||
import { removeJSRunner, setJSRunner } from "./helpers/javascript"
|
import { removeJSRunner, setJSRunner } from "./helpers/javascript"
|
||||||
|
|
||||||
import manifest from "./manifest.json"
|
import manifest from "./manifest.json"
|
||||||
import { Log, ProcessOptions } from "./types"
|
import { Log, ProcessOptions } from "./types"
|
||||||
import { UserScriptError } from "./errors"
|
import { UserScriptError } from "./errors"
|
||||||
|
import { isTest } from "./environment"
|
||||||
|
|
||||||
export type { Log, LogType } from "./types"
|
export type { Log, LogType } from "./types"
|
||||||
export { setTestingBackendJS } from "./environment"
|
export { setTestingBackendJS } from "./environment"
|
||||||
|
@ -507,15 +508,15 @@ export function convertToJS(hbs: string) {
|
||||||
export { JsTimeoutError, UserScriptError } from "./errors"
|
export { JsTimeoutError, UserScriptError } from "./errors"
|
||||||
|
|
||||||
export function browserJSSetup() {
|
export function browserJSSetup() {
|
||||||
/**
|
// tests are in jest - we need to use node VM for these
|
||||||
* Use polyfilled vm to run JS scripts in a browser Env
|
const jsSandbox = isTest() ? vm : browserVM
|
||||||
*/
|
// Use polyfilled vm to run JS scripts in a browser Env
|
||||||
setJSRunner((js: string, context: Record<string, any>) => {
|
setJSRunner((js: string, context: Record<string, any>) => {
|
||||||
vm.createContext(context)
|
jsSandbox.createContext(context)
|
||||||
|
|
||||||
const wrappedJs = frontendWrapJS(js)
|
const wrappedJs = frontendWrapJS(js)
|
||||||
|
|
||||||
const result = vm.runInNewContext(wrappedJs, context)
|
const result = jsSandbox.runInNewContext(wrappedJs, context)
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
throw new UserScriptError(result.error)
|
throw new UserScriptError(result.error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue