(lang, filters)
| 139 | } |
| 140 | |
| 141 | export 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 | |
| 168 | async function populateTestsForLang({ lang, challenges, meta }) { |
| 169 | // We have to dynamically import this because otherwise it will not be mocked. |
no test coverage detected