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:
committed by
GitHub
parent
e0a5fcdb8e
commit
4cc20172c5
@ -1,7 +1,7 @@
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
createChallenge,
|
||||
generateChallengeCreator,
|
||||
hasEnglishSource,
|
||||
createCommentMap
|
||||
} = require('./getChallenges');
|
||||
@ -12,21 +12,25 @@ const MISSING_CHALLENGE_PATH = 'no/challenge.md';
|
||||
const basePath = '__fixtures__';
|
||||
|
||||
describe('create non-English challenge', () => {
|
||||
describe('createChallenge', () => {
|
||||
it('throws if lang is an invalid language', async () => {
|
||||
await expect(
|
||||
createChallenge(basePath, EXISTING_CHALLENGE_PATH, 'notlang', {})
|
||||
).rejects.toThrow('notlang is not a accepted language');
|
||||
});
|
||||
it('throws an error if the source challenge is missing', async () => {
|
||||
await expect(
|
||||
createChallenge(basePath, MISSING_CHALLENGE_PATH, 'chinese', {})
|
||||
).rejects.toThrow(
|
||||
`Missing English challenge for
|
||||
describe('generateChallengeCreator', () => {
|
||||
describe('createChallenge', () => {
|
||||
it('throws if lang is an invalid language', async () => {
|
||||
const createChallenge = generateChallengeCreator(basePath, 'notlang');
|
||||
await expect(
|
||||
createChallenge(EXISTING_CHALLENGE_PATH, {})
|
||||
).rejects.toThrow('notlang is not a accepted language');
|
||||
});
|
||||
it('throws an error if the source challenge is missing', async () => {
|
||||
const createChallenge = generateChallengeCreator(basePath, 'chinese');
|
||||
await expect(
|
||||
createChallenge(MISSING_CHALLENGE_PATH, {})
|
||||
).rejects.toThrow(
|
||||
`Missing English challenge for
|
||||
${MISSING_CHALLENGE_PATH}
|
||||
It should be in
|
||||
`
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('hasEnglishSource', () => {
|
||||
@ -69,9 +73,15 @@ It should be in
|
||||
expect(typeof createCommentMap(dictionaryDir)).toBe('object');
|
||||
});
|
||||
|
||||
it('throws if an entry is missing', () => {
|
||||
expect.assertions(1);
|
||||
expect(() => createCommentMap(incompleteDictDir)).toThrow();
|
||||
it('fallback to the untranslated string', () => {
|
||||
expect.assertions(2);
|
||||
const commentMap = createCommentMap(incompleteDictDir);
|
||||
expect(commentMap['To be translated one'].spanish).toEqual(
|
||||
'Spanish translation one'
|
||||
);
|
||||
expect(commentMap['To be translated two'].spanish).toEqual(
|
||||
'To be translated two'
|
||||
);
|
||||
});
|
||||
|
||||
it('returns an object with an expected form', () => {
|
||||
|
Reference in New Issue
Block a user