Allow skipping tests

This commit is contained in:
Adria Navarro 2024-02-01 10:58:20 +01:00
parent 82db76627f
commit 4461c49f48
2 changed files with 27 additions and 23 deletions

View File

@ -45,5 +45,6 @@ describe("jsRunner", () => {
runJsHelpersTests({ runJsHelpersTests({
funcWrap: (func: any) => config.doInContext(config.getAppId(), func), funcWrap: (func: any) => config.doInContext(config.getAppId(), func),
testsToSkip: ["random", "uuid"],
}) })
}) })

View File

@ -60,9 +60,8 @@ const getParsedManifest = () => {
} }
module.exports.getParsedManifest = getParsedManifest module.exports.getParsedManifest = getParsedManifest
module.exports.runJsHelpersTests = ( module.exports.runJsHelpersTests = ({ funcWrap, testsToSkip } = {}) => {
{ funcWrap } = { funcWrap: delegate => delegate() } funcWrap = funcWrap || (delegate => delegate())
) => {
const manifest = getParsedManifest() const manifest = getParsedManifest()
const processJS = (js, context) => { const processJS = (js, context) => {
@ -81,28 +80,32 @@ module.exports.runJsHelpersTests = (
}, {}) }, {})
describe.each(Object.keys(jsExamples))("%s", collection => { describe.each(Object.keys(jsExamples))("%s", collection => {
it.each( const examplesToRun = jsExamples[collection]
jsExamples[collection].filter( .filter(([_, { requiresHbsBody }]) => !requiresHbsBody)
([_, { requiresHbsBody }]) => !requiresHbsBody .filter(([key]) => !testsToSkip?.includes(key))
)
)("%s", async (_, { hbs, js }) => {
const context = {
double: i => i * 2,
isString: x => typeof x === "string",
}
const arrays = hbs.match(/\[[^/\]]+\]/) examplesToRun.length &&
arrays?.forEach((arrayString, i) => { it.each(examplesToRun)("%s", async (_, { hbs, js }) => {
hbs = hbs.replace(new RegExp(escapeRegExp(arrayString)), `array${i}`) const context = {
context[`array${i}`] = JSON.parse(arrayString.replace(/\'/g, '"')) double: i => i * 2,
isString: x => typeof x === "string",
}
const arrays = hbs.match(/\[[^/\]]+\]/)
arrays?.forEach((arrayString, i) => {
hbs = hbs.replace(
new RegExp(escapeRegExp(arrayString)),
`array${i}`
)
context[`array${i}`] = JSON.parse(arrayString.replace(/\'/g, '"'))
})
let convertedJs = convertToJS(hbs)
let result = await processJS(convertedJs, context)
result = result.replace(/ /g, " ")
expect(result).toEqual(js)
}) })
let convertedJs = convertToJS(hbs)
let result = await processJS(convertedJs, context)
result = result.replace(/ /g, " ")
expect(result).toEqual(js)
})
}) })
}) })
} }