1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Fix javacript runs

This commit is contained in:
Adria Navarro 2024-02-09 10:33:09 +01:00
parent 2cde033783
commit 7aee57eb6a

View file

@ -1,10 +1,30 @@
const { processStringSync, encodeJSBinding } = require("../src/index.js")
const vm = require("vm")
const {
processStringSync,
encodeJSBinding,
setJSRunner,
} = require("../src/index.js")
const { UUID_REGEX } = require("./constants")
const processJS = (js, context) => {
return processStringSync(encodeJSBinding(js), context)
}
describe("Javascript", () => {
beforeAll(() => {
setJSRunner((js, context) => {
context = {
...context,
alert: undefined,
setInterval: undefined,
setTimeout: undefined,
}
vm.createContext(context)
return vm.runInNewContext(js, context, { timeout: 1000 })
})
})
describe("Test the JavaScript helper", () => {
it("should execute a simple expression", () => {
const output = processJS(`return 1 + 2`)
@ -147,3 +167,4 @@ describe("check JS helpers", () => {
expect(output).toMatch(UUID_REGEX)
})
})
})