MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / createTestRunner

Function createTestRunner

curriculum/src/test/test-challenges.js:392–443  ·  view source on GitHub ↗
(
  challenge,
  solutionFiles,
  buildChallenge,
  solutionFromNext
)

Source from the content-addressed store, hash-verified

390}
391
392async function createTestRunner(
393 challenge,
394 solutionFiles,
395 buildChallenge,
396 solutionFromNext
397) {
398 const { runnerTypes } = await import('@freecodecamp/challenge-builder/build');
399
400 const challengeFiles = replaceChallengeFilesContentsWithSolutions(
401 challenge.challengeFiles,
402 solutionFiles
403 );
404
405 const { build, sources, loadEnzyme } = await buildChallenge(
406 {
407 ...challenge,
408 challengeFiles
409 },
410 { usesTestRunner: true }
411 );
412
413 if (!page) throw new Error('Browser page is not ready yet');
414
415 const evaluator = await getContextEvaluator({
416 // passing in challengeId so it's easier to debug timeouts
417 challengeId: challenge.id,
418 build,
419 sources,
420 type: runnerTypes[challenge.challengeType],
421 loadEnzyme,
422 hooks: challenge.hooks
423 });
424
425 return async tests => {
426 const testStrings = tests.map(test => test.testString);
427
428 const results = await evaluator.evaluate(testStrings, 5000);
429 for (let i = 0; i < results.length; i++) {
430 const { err } = results[i];
431 let { text } = tests[i];
432 if (err) {
433 text = 'Test text: ' + text;
434 const newMessage = solutionFromNext
435 ? 'Check next step for solution!\n' + text
436 : text;
437 err.message = `${newMessage}
438Original message: ${err.message}`;
439 throw err;
440 }
441 }
442 };
443}
444
445function replaceChallengeFilesContentsWithSolutions(
446 challengeFiles,

Callers 1

populateTestsForLangFunction · 0.85

Calls 3

buildChallengeFunction · 0.85
getContextEvaluatorFunction · 0.85

Tested by

no test coverage detected