Add tests.
This commit is contained in:
parent
93b18b81e0
commit
a866677080
|
@ -2135,5 +2135,48 @@ describe.each([
|
|||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should not carry over context between formulas", async () => {
|
||||
const js = Buffer.from(`return $("[text]");`).toString("base64")
|
||||
const table = await config.createTable({
|
||||
name: "table",
|
||||
type: "table",
|
||||
schema: {
|
||||
text: {
|
||||
name: "text",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
formula: {
|
||||
name: "formula",
|
||||
type: FieldType.FORMULA,
|
||||
formula: `{{ js "${js}"}}`,
|
||||
formulaType: FormulaType.DYNAMIC,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await config.api.row.save(table._id!, { text: `foo${i}` })
|
||||
}
|
||||
|
||||
const { rows } = await config.api.row.search(table._id!)
|
||||
expect(rows).toHaveLength(10)
|
||||
|
||||
const formulaValues = rows.map(r => r.formula)
|
||||
expect(formulaValues).toEqual(
|
||||
expect.arrayContaining([
|
||||
"foo0",
|
||||
"foo1",
|
||||
"foo2",
|
||||
"foo3",
|
||||
"foo4",
|
||||
"foo5",
|
||||
"foo6",
|
||||
"foo7",
|
||||
"foo8",
|
||||
"foo9",
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -24,13 +24,11 @@ export function init() {
|
|||
const bbCtx = context.getCurrentContext()!
|
||||
|
||||
if (!bbCtx.vm) {
|
||||
const vm = new IsolatedVM({
|
||||
bbCtx.vm = new IsolatedVM({
|
||||
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
|
||||
invocationTimeout: env.JS_PER_INVOCATION_TIMEOUT_MS,
|
||||
isolateAccumulatedTimeout: env.JS_PER_REQUEST_TIMEOUT_MS,
|
||||
}).withHelpers()
|
||||
|
||||
bbCtx.vm = vm
|
||||
}
|
||||
const { helpers, ...rest } = ctx
|
||||
return bbCtx.vm.withContext(rest, () => bbCtx.vm!.execute(js))
|
||||
|
|
Loading…
Reference in New Issue