diff --git a/packages/server/src/jsRunner/tests/jsRunner.spec.ts b/packages/server/src/jsRunner/tests/jsRunner.spec.ts index 35c01a5a8a..ddef60a80e 100644 --- a/packages/server/src/jsRunner/tests/jsRunner.spec.ts +++ b/packages/server/src/jsRunner/tests/jsRunner.spec.ts @@ -19,17 +19,28 @@ import { processStringSync, encodeJSBinding } from "@budibase/string-templates" const { runJsHelpersTests } = require("@budibase/string-templates/test/utils") import tk from "timekeeper" +import { init } from ".." +import TestConfiguration from "../../tests/utilities/TestConfiguration" tk.freeze("2021-01-21T12:00:00") describe("jsRunner", () => { + const config = new TestConfiguration() + + beforeAll(async () => { + init() + await config.init() + }) + 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", () => { - const output = processJS(`return 1 + 2`) + it("it can run a basic javascript", async () => { + const output = await processJS(`return 1 + 2`) expect(output).toBe(3) }) - runJsHelpersTests() + runJsHelpersTests((func: any) => config.doInContext(config.getAppId(), func)) }) diff --git a/packages/string-templates/test/utils.js b/packages/string-templates/test/utils.js index 8b8943c776..33f6c6d6b6 100644 --- a/packages/string-templates/test/utils.js +++ b/packages/string-templates/test/utils.js @@ -60,11 +60,11 @@ const getParsedManifest = () => { } module.exports.getParsedManifest = getParsedManifest -module.exports.runJsHelpersTests = () => { +module.exports.runJsHelpersTests = (funcWrap = delegate => delegate()) => { const manifest = getParsedManifest() const processJS = (js, context) => { - return processStringSync(encodeJSBinding(js), context) + return funcWrap(() => processStringSync(encodeJSBinding(js), context)) } function escapeRegExp(string) {