From 4461c49f48e3efb13fef5c4c0f839b2b0275ed1f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 1 Feb 2024 10:58:20 +0100 Subject: [PATCH] Allow skipping tests --- .../src/jsRunner/tests/jsRunner.spec.ts | 1 + packages/string-templates/test/utils.js | 49 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/server/src/jsRunner/tests/jsRunner.spec.ts b/packages/server/src/jsRunner/tests/jsRunner.spec.ts index 56314c9565..876ada5ee0 100644 --- a/packages/server/src/jsRunner/tests/jsRunner.spec.ts +++ b/packages/server/src/jsRunner/tests/jsRunner.spec.ts @@ -45,5 +45,6 @@ describe("jsRunner", () => { runJsHelpersTests({ funcWrap: (func: any) => config.doInContext(config.getAppId(), func), + testsToSkip: ["random", "uuid"], }) }) diff --git a/packages/string-templates/test/utils.js b/packages/string-templates/test/utils.js index 04faffb27d..2375c5868f 100644 --- a/packages/string-templates/test/utils.js +++ b/packages/string-templates/test/utils.js @@ -60,9 +60,8 @@ const getParsedManifest = () => { } module.exports.getParsedManifest = getParsedManifest -module.exports.runJsHelpersTests = ( - { funcWrap } = { funcWrap: delegate => delegate() } -) => { +module.exports.runJsHelpersTests = ({ funcWrap, testsToSkip } = {}) => { + funcWrap = funcWrap || (delegate => delegate()) const manifest = getParsedManifest() const processJS = (js, context) => { @@ -81,28 +80,32 @@ module.exports.runJsHelpersTests = ( }, {}) describe.each(Object.keys(jsExamples))("%s", collection => { - it.each( - jsExamples[collection].filter( - ([_, { requiresHbsBody }]) => !requiresHbsBody - ) - )("%s", async (_, { hbs, js }) => { - const context = { - double: i => i * 2, - isString: x => typeof x === "string", - } + const examplesToRun = jsExamples[collection] + .filter(([_, { requiresHbsBody }]) => !requiresHbsBody) + .filter(([key]) => !testsToSkip?.includes(key)) - 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, '"')) + examplesToRun.length && + it.each(examplesToRun)("%s", async (_, { hbs, js }) => { + const context = { + 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) - }) }) }) }