MCPcopy
hub / github.com/freeCodeCamp/freeCodeCamp / getChallenges

Function getChallenges

curriculum/src/test/test-challenges.js:141–166  ·  view source on GitHub ↗
(lang, filters)

Source from the content-addressed store, hash-verified

139}
140
141export async function getChallenges(lang, filters) {
142 const challenges = await getChallengesForLang(lang, filters).then(
143 curriculum => {
144 // If there are filters, we're testing a single challenge or block, so we
145 // can skip the validation.
146 if (isEmpty(filters)) {
147 const result = curriculumSchemaValidator(curriculum);
148 if (result.error)
149 throw new Error(
150 `Curriculum validation failed: ${result.error.message}`
151 );
152 }
153 return Object.keys(curriculum)
154 .map(key => curriculum[key].blocks)
155 .reduce((challengeArray, superBlock) => {
156 const challengesForBlock = Object.keys(superBlock).map(
157 key => superBlock[key].challenges
158 );
159 return [...challengeArray, ...flatten(challengesForBlock)];
160 }, []);
161 }
162 );
163 // This matches the order Gatsby uses (via a GraphQL query). Ideally both
164 // should be sourced and sorted using a single query, but we're not there yet.
165 return sortChallenges(challenges);
166}
167
168async function populateTestsForLang({ lang, challenges, meta }) {
169 // We have to dynamically import this because otherwise it will not be mocked.

Callers 4

defineTestsForBlockFunction · 0.70

Calls 1

getChallengesForLangFunction · 0.85

Tested by

no test coverage detected