feat: allow next challenge's seed to be a solution (#39145)
* feat: allow next challenge's seed to be a solution
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
4f1be63055
commit
fd7a8c0d5e
@ -23,7 +23,7 @@ const {
|
||||
|
||||
const { assert, AssertionError } = require('chai');
|
||||
const Mocha = require('mocha');
|
||||
const { flatten } = require('lodash');
|
||||
const { flatten, isEmpty } = require('lodash');
|
||||
|
||||
const jsdom = require('jsdom');
|
||||
|
||||
@ -51,6 +51,7 @@ const {
|
||||
} = require('../../client/src/templates/Challenges/utils/build');
|
||||
|
||||
const { createPoly } = require('../../utils/polyvinyl');
|
||||
const { sortChallenges } = require('./utils/sort-challenges');
|
||||
|
||||
const testEvaluator = require('../../client/config/test-evaluator').filename;
|
||||
|
||||
@ -226,7 +227,9 @@ async function getChallenges(lang) {
|
||||
return [...challengeArray, ...flatten(challengesForBlock)];
|
||||
}, [])
|
||||
);
|
||||
return challenges;
|
||||
// This matches the order Gatsby uses (via a GraphQL query). Ideally both
|
||||
// should be sourced and sorted using a single query, but we're not there yet.
|
||||
return sortChallenges(challenges);
|
||||
}
|
||||
|
||||
function validateBlock(challenge) {
|
||||
@ -245,7 +248,7 @@ function populateTestsForLang({ lang, challenges, meta }) {
|
||||
|
||||
describe(`Check challenges (${lang})`, function() {
|
||||
this.timeout(5000);
|
||||
challenges.forEach(challenge => {
|
||||
challenges.forEach((challenge, id) => {
|
||||
const dashedBlockName = dasherize(challenge.block);
|
||||
describe(challenge.block || 'No block', function() {
|
||||
describe(challenge.title || 'No title', function() {
|
||||
@ -367,6 +370,15 @@ function populateTestsForLang({ lang, challenges, meta }) {
|
||||
});
|
||||
|
||||
let { solutions = [] } = challenge;
|
||||
// if there are no solutions in the challenge, it's assumed the next
|
||||
// challenge's seed will be a solution to the current challenge.
|
||||
// This is expected to happen in the project based curriculum.
|
||||
if (isEmpty(solutions)) {
|
||||
const nextChallenge = challenges[id + 1];
|
||||
if (nextChallenge) {
|
||||
solutions = [nextChallenge.files[0].contents];
|
||||
}
|
||||
}
|
||||
const noSolution = new RegExp('// solution required');
|
||||
solutions = solutions.filter(
|
||||
solution => !!solution && !noSolution.test(solution)
|
||||
|
Reference in New Issue
Block a user