Add helpers in order to fix tests
This commit is contained in:
parent
4df738acb7
commit
fde2af9a28
|
@ -0,0 +1,24 @@
|
||||||
|
import { utils } from "@budibase/shared-core"
|
||||||
|
import environment from "../../environment"
|
||||||
|
import fs from "fs"
|
||||||
|
|
||||||
|
export enum BundleType {
|
||||||
|
HELPERS = "helpers",
|
||||||
|
}
|
||||||
|
|
||||||
|
const bundleSourceCode = {
|
||||||
|
[BundleType.HELPERS]: "../bundles/index-helpers.ivm.bundle.js",
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadBundle(type: BundleType) {
|
||||||
|
if (environment.isJest()) {
|
||||||
|
return fs.readFileSync(require.resolve(bundleSourceCode[type]), "utf-8")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case BundleType.HELPERS:
|
||||||
|
return require("../bundles/index-helpers.ivm.bundle.js")
|
||||||
|
default:
|
||||||
|
utils.unreachable(type)
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import tracer from "dd-trace"
|
||||||
import url from "url"
|
import url from "url"
|
||||||
import crypto from "crypto"
|
import crypto from "crypto"
|
||||||
import querystring from "querystring"
|
import querystring from "querystring"
|
||||||
|
import { BundleType, loadBundle } from "./bundles"
|
||||||
|
|
||||||
class ExecutionTimeoutError extends Error {
|
class ExecutionTimeoutError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
|
@ -15,6 +16,7 @@ class ExecutionTimeoutError extends Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
|
const helpersSource = loadBundle(BundleType.HELPERS)
|
||||||
setJSRunner((js: string, ctx: Record<string, any>) => {
|
setJSRunner((js: string, ctx: Record<string, any>) => {
|
||||||
return tracer.trace("runJS", {}, span => {
|
return tracer.trace("runJS", {}, span => {
|
||||||
try {
|
try {
|
||||||
|
@ -74,7 +76,6 @@ export function init() {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const helpersSource = require("./bundles/index-helpers.ivm.bundle.js")
|
|
||||||
const helpersModule = jsIsolate.compileModuleSync(
|
const helpersModule = jsIsolate.compileModuleSync(
|
||||||
`${injectedRequire};${helpersSource}`
|
`${injectedRequire};${helpersSource}`
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue