test: enable tests for steps (#44550)
* fix: handle missing solutions correctly Rather than creating an [[]] the parser now creates [] which isEmpty(). This makes the test suite check the next challenge for a solution. In addition, the logic for testing solutions was fixed. * chore: update snapshots * test: build new superblock in node.js-tests CI * test: allow forward slash in superblock slug * fix: borked tests oops * test: ignore duplicated projects * fix: i did not break these shaun did :) * fix: idIndex is index of id not id Co-authored-by: Nicholas Carrigan <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
4be4bf3624
commit
36363f277d
@ -161,8 +161,10 @@ async function setup() {
|
||||
// as they appear in the list of challenges
|
||||
const blocks = challenges.map(({ block }) => block);
|
||||
const superBlocks = challenges.map(({ superBlock }) => superBlock);
|
||||
const targetBlockStrings = [...new Set(blocks)];
|
||||
const targetSuperBlockStrings = [...new Set(superBlocks)];
|
||||
const targetBlockStrings = [...new Set(blocks.filter(el => Boolean(el)))];
|
||||
const targetSuperBlockStrings = [
|
||||
...new Set(superBlocks.filter(el => Boolean(el)))
|
||||
];
|
||||
|
||||
// the next few statements will filter challenges based on command variables
|
||||
if (process.env.npm_config_superblock) {
|
||||
@ -497,24 +499,26 @@ ${inspect(commentMap)}
|
||||
// This is expected to happen in the project based curriculum.
|
||||
|
||||
const nextChallenge = challenges[id + 1];
|
||||
// TODO: can this be dried out, ideally by removing the redux
|
||||
// handler?
|
||||
|
||||
if (nextChallenge) {
|
||||
const solutionFiles = cloneDeep(nextChallenge.challengeFiles);
|
||||
solutionFiles.forEach(challengeFile => {
|
||||
challengeFile.editableContents = getLines(
|
||||
challengeFile.contents,
|
||||
challenge.challengeFiles.find(
|
||||
x =>
|
||||
x.ext === challengeFile.ext &&
|
||||
x.name === challengeFile.name
|
||||
).editableRegionBoundaries
|
||||
);
|
||||
});
|
||||
solutions = [solutionFiles];
|
||||
const solutionFilesWithEditableContents = solutionFiles.map(
|
||||
file => ({
|
||||
...file,
|
||||
editableContents: getLines(
|
||||
file.contents,
|
||||
file.editableRegionBoundaries
|
||||
)
|
||||
})
|
||||
);
|
||||
// Since there is only one seed, there can only be one solution,
|
||||
// but the tests assume solutions is an array.
|
||||
solutions = [solutionFilesWithEditableContents];
|
||||
solutionFromNext = true;
|
||||
} else {
|
||||
throw Error('solution omitted');
|
||||
throw Error(
|
||||
`solution omitted for ${challenge.superBlock} ${challenge.block} ${challenge.title}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,15 +571,11 @@ async function createTestRunner(
|
||||
solutionFromNext
|
||||
) {
|
||||
const { required = [], template, removeComments } = challenge;
|
||||
// we should avoid modifying challenge, as it gets reused:
|
||||
const challengeFiles = cloneDeep(challenge.challengeFiles);
|
||||
solutionFiles.forEach(solutionFile => {
|
||||
const challengeFile = challengeFiles.find(
|
||||
x => x.ext === solutionFile.ext && x.name === solutionFile.name
|
||||
);
|
||||
challengeFile.contents = solutionFile.contents;
|
||||
challengeFile.editableContents = solutionFile.editableContents;
|
||||
});
|
||||
|
||||
const challengeFiles = replaceChallengeFilesContentsWithSolutions(
|
||||
challenge.challengeFiles,
|
||||
solutionFiles
|
||||
);
|
||||
|
||||
const { build, sources, loadEnzyme } = await buildChallenge({
|
||||
challengeFiles,
|
||||
@ -615,6 +615,25 @@ async function createTestRunner(
|
||||
};
|
||||
}
|
||||
|
||||
function replaceChallengeFilesContentsWithSolutions(
|
||||
challengeFiles,
|
||||
solutionFiles
|
||||
) {
|
||||
return challengeFiles.map(file => {
|
||||
const matchingSolutionFile = solutionFiles.find(
|
||||
({ ext, name }) => ext === file.ext && file.name === name
|
||||
);
|
||||
if (!matchingSolutionFile) {
|
||||
throw Error(`No matching solution file found`);
|
||||
}
|
||||
return {
|
||||
...file,
|
||||
contents: matchingSolutionFile.contents,
|
||||
editableContents: matchingSolutionFile.editableContents
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function getContextEvaluator(build, sources, code, loadEnzyme) {
|
||||
await initializeTestRunner(build, sources, code, loadEnzyme);
|
||||
|
||||
|
Reference in New Issue
Block a user