From 5d5dafbd1eff2f0efbf0c9e93b0d6464c665b536 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 16 Dec 2024 08:08:38 +0100 Subject: [PATCH] fix(tools): sync up unit tests with client tests (#57512) --- .../src/templates/Challenges/utils/build.ts | 2 +- curriculum/test/test-challenges.js | 30 ++++++------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/client/src/templates/Challenges/utils/build.ts b/client/src/templates/Challenges/utils/build.ts index 2baa8f63e12..d8210abfe33 100644 --- a/client/src/templates/Challenges/utils/build.ts +++ b/client/src/templates/Challenges/utils/build.ts @@ -93,7 +93,7 @@ function buildSourceMap(challengeFiles: ChallengeFile[]): Source | undefined { return source; } -const buildFunctions = { +export const buildFunctions = { [challengeTypes.js]: buildJSChallenge, [challengeTypes.jsProject]: buildJSChallenge, [challengeTypes.html]: buildDOMChallenge, diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index bedb892f0f1..ac6a9e5d00e 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -25,8 +25,9 @@ require('@babel/register')({ }); const { buildDOMChallenge, - buildJSChallenge, - buildPythonChallenge + buildPythonChallenge, + buildChallenge, + buildFunctions } = require('../../client/src/templates/Challenges/utils/build'); const { WorkerExecutor @@ -407,18 +408,6 @@ function populateTestsForLang({ lang, challenges, meta, superBlocks }) { return; } - // TODO(after python PR): simplify pipeline and sync with client. - // buildChallengeData should be called and any errors handled. - // canBuildChallenge does not need to exist independently. - const buildChallenge = - { - [challengeTypes.js]: buildJSChallenge, - [challengeTypes.jsProject]: buildJSChallenge, - [challengeTypes.python]: buildPythonChallenge, - [challengeTypes.multifilePythonCertProject]: - buildPythonChallenge - }[challengeType] ?? buildDOMChallenge; - // The python tests are (currently) slow, so we give them more time. const timePerTest = challengeType === challengeTypes.python ? 10000 : 5000; @@ -563,8 +552,6 @@ async function createTestRunner( buildChallenge, solutionFromNext ) { - const { required = [], template } = challenge; - const challengeFiles = replaceChallengeFilesContentsWithSolutions( challenge.challengeFiles, solutionFiles @@ -572,9 +559,8 @@ async function createTestRunner( const { build, sources, loadEnzyme } = await buildChallenge( { - challengeFiles, - required, - template + ...challenge, + challengeFiles }, { usesTestRunner: true } ); @@ -585,8 +571,10 @@ async function createTestRunner( original: sources.original }; - const runsInBrowser = buildChallenge === buildDOMChallenge; - const runsInPythonWorker = buildChallenge === buildPythonChallenge; + const buildFunction = buildFunctions[challenge.challengeType]; + + const runsInBrowser = buildFunction === buildDOMChallenge; + const runsInPythonWorker = buildFunction === buildPythonChallenge; const evaluator = await (runsInBrowser ? getContextEvaluator(build, sources, code, loadEnzyme)