fix: fallback to english challenges (#45635)

* fix: fallback to english challenges

All challenges will use the english version if a translated file is not
available.  SHOW_NEW_CURRICULUM still gates what's shown in the client.

* refactor: use closures to simplify createChallenge

* refactor: remove messy destructure

* refactor: add meta via helper

* fix: fallback to [] for meta.required

* fix: repair challenge.block

* refactor: use CONST_CASE for meta + challenge dirs

* fix: catch empty superblocks immediately

* fix: clean up path.resolves

* fix: invalid syntax in JS project steps

* fix: default to english comments and relax tests

Instead of always throwing errors when a comment is not translated, the
tests now warn while SHOW_UPCOMING_CHANGES is true, so that tests will
pass while we're developing and allow translators time to work.

They still throw when SHOW_UPCOMING_CHANGES is false to catch issues
in production

* test: update createCommentMap test

* refactor: delete stale comment

* refactor: clarify validate with explanatory consts

* feat: throw if audited cert falls back to english

* fix: stop testing upcoming localized curriculum
This commit is contained in:
Oliver Eyton-Williams
2022-04-15 16:17:49 +02:00
committed by GitHub
parent e0a5fcdb8e
commit 4cc20172c5
10 changed files with 171 additions and 134 deletions

View File

@ -317,13 +317,13 @@ function populateTestsForLang({ lang, challenges, meta }) {
// Note: the title in meta.json are purely for human readability and
// do not include translations, so we do not validate against them.
it('Matches an ID in meta.json', function () {
const index = meta[dashedBlockName].challengeOrder.findIndex(
const index = meta[dashedBlockName]?.challengeOrder?.findIndex(
arr => arr[0] === challenge.id
);
if (index < 0) {
throw new AssertionError(
`Cannot find ID "${challenge.id}" in meta.json file`
`Cannot find ID "${challenge.id}" in meta.json file for block "${dashedBlockName}"`
);
}
});
@ -370,11 +370,14 @@ function populateTestsForLang({ lang, challenges, meta }) {
// currently have the text of a comment elsewhere. If that happens
// we can handle that challenge separately.
TRANSLATABLE_COMMENTS.forEach(comment => {
const errorText = `English comment '${comment}' should be replaced with its translation`;
challenge.challengeFiles.forEach(challengeFile => {
if (challengeFile.contents.includes(comment))
throw Error(
`English comment '${comment}' should be replaced with its translation`
);
if (process.env.SHOW_UPCOMING_CHANGES == 'true') {
console.warn(errorText);
} else {
throw Error(errorText);
}
});
});
@ -414,7 +417,10 @@ function populateTestsForLang({ lang, challenges, meta }) {
if (isEmpty(challenge.__commentCounts) && isEmpty(commentMap))
return;
if (!isEqual(commentMap, challenge.__commentCounts))
if (
process.env.SHOW_NEW_CURRICULUM !== 'true' &&
!isEqual(commentMap, challenge.__commentCounts)
)
throw Error(`Mismatch in ${challenge.title}. Replaced comments:
${inspect(challenge.__commentCounts)}
Comments in translated text: