Adding the ability to configure whether or not string templates is testing backend JS or frontend.
This commit is contained in:
parent
9c65f1ab41
commit
98bd824d7a
|
@ -50,9 +50,11 @@ 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
|
||||||
|
|
|
@ -9,3 +9,15 @@ function isJest() {
|
||||||
export function isTest() {
|
export function isTest() {
|
||||||
return isJest()
|
return isJest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isJSAllowed = () => {
|
||||||
|
return process && !process.env.NO_JS
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isTestingBackendJS = () => {
|
||||||
|
return process && process.env.BACKEND_JS
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setTestingBackendJS = () => {
|
||||||
|
process.env.BACKEND_JS = "1"
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { Log, ProcessOptions } from "./types"
|
||||||
import { UserScriptError } from "./errors"
|
import { UserScriptError } from "./errors"
|
||||||
|
|
||||||
export type { Log, LogType } from "./types"
|
export type { Log, LogType } from "./types"
|
||||||
|
export { setTestingBackendJS } from "./environment"
|
||||||
export { helpersToRemoveForJs, getJsHelperList } from "./helpers/list"
|
export { helpersToRemoveForJs, getJsHelperList } from "./helpers/list"
|
||||||
export { FIND_ANY_HBS_REGEX } from "./utilities"
|
export { FIND_ANY_HBS_REGEX } from "./utilities"
|
||||||
export { setJSRunner, setOnErrorLog } from "./helpers/javascript"
|
export { setJSRunner, setOnErrorLog } from "./helpers/javascript"
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
|
import { isTest, isTestingBackendJS } from "./environment"
|
||||||
|
|
||||||
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
|
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
|
||||||
|
|
||||||
export const FIND_HBS_REGEX = /{{([^{].*?)}}/g
|
export const FIND_HBS_REGEX = /{{([^{].*?)}}/g
|
||||||
export const FIND_ANY_HBS_REGEX = /{?{{([^{].*?)}}}?/g
|
export const FIND_ANY_HBS_REGEX = /{?{{([^{].*?)}}}?/g
|
||||||
export const FIND_TRIPLE_HBS_REGEX = /{{{([^{].*?)}}}/g
|
export const FIND_TRIPLE_HBS_REGEX = /{{{([^{].*?)}}}/g
|
||||||
|
|
||||||
const isJest = () => typeof jest !== "undefined"
|
|
||||||
|
|
||||||
export const isBackendService = () => {
|
export const isBackendService = () => {
|
||||||
|
// allow configuring backend JS mode when testing - we default to assuming
|
||||||
|
// frontend, but need a method to control this
|
||||||
|
if (isTest() && isTestingBackendJS()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
// We consider the tests for string-templates to be frontend, so that they
|
// We consider the tests for string-templates to be frontend, so that they
|
||||||
// test the frontend JS functionality.
|
// test the frontend JS functionality.
|
||||||
if (isJest()) {
|
if (isTest()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return typeof window === "undefined"
|
return typeof window === "undefined"
|
||||||
|
|
Loading…
Reference in New Issue