Register server helpers
This commit is contained in:
parent
b96ca1cf54
commit
e6ae364918
|
@ -19,17 +19,28 @@ import { processStringSync, encodeJSBinding } from "@budibase/string-templates"
|
||||||
const { runJsHelpersTests } = require("@budibase/string-templates/test/utils")
|
const { runJsHelpersTests } = require("@budibase/string-templates/test/utils")
|
||||||
|
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
|
import { init } from ".."
|
||||||
|
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
||||||
tk.freeze("2021-01-21T12:00:00")
|
tk.freeze("2021-01-21T12:00:00")
|
||||||
|
|
||||||
describe("jsRunner", () => {
|
describe("jsRunner", () => {
|
||||||
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
init()
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
const processJS = (js: string, context?: object) => {
|
const processJS = (js: string, context?: object) => {
|
||||||
return processStringSync(encodeJSBinding(js), context || {})
|
return config.doInContext(config.getAppId(), async () =>
|
||||||
|
processStringSync(encodeJSBinding(js), context || {})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
it("it can run a basic javascript", () => {
|
it("it can run a basic javascript", async () => {
|
||||||
const output = processJS(`return 1 + 2`)
|
const output = await processJS(`return 1 + 2`)
|
||||||
expect(output).toBe(3)
|
expect(output).toBe(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
runJsHelpersTests()
|
runJsHelpersTests((func: any) => config.doInContext(config.getAppId(), func))
|
||||||
})
|
})
|
||||||
|
|
|
@ -60,11 +60,11 @@ const getParsedManifest = () => {
|
||||||
}
|
}
|
||||||
module.exports.getParsedManifest = getParsedManifest
|
module.exports.getParsedManifest = getParsedManifest
|
||||||
|
|
||||||
module.exports.runJsHelpersTests = () => {
|
module.exports.runJsHelpersTests = (funcWrap = delegate => delegate()) => {
|
||||||
const manifest = getParsedManifest()
|
const manifest = getParsedManifest()
|
||||||
|
|
||||||
const processJS = (js, context) => {
|
const processJS = (js, context) => {
|
||||||
return processStringSync(encodeJSBinding(js), context)
|
return funcWrap(() => processStringSync(encodeJSBinding(js), context))
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string) {
|
||||||
|
|
Loading…
Reference in New Issue