diff --git a/curriculum/gulpfile.js b/curriculum/gulpfile.js index d5a6161183..c53cd541eb 100644 --- a/curriculum/gulpfile.js +++ b/curriculum/gulpfile.js @@ -4,7 +4,7 @@ const through2 = require('through2'); const { locale } = require('../config/env.json'); const { getChallengesForLang } = require('./getChallenges'); -const { testedLangs } = require('./utils'); +const { testedLang } = require('./utils'); const lintMarkdown = require('../tools/scripts/lint'); /** @@ -28,7 +28,7 @@ function watchFiles() { } function lint() { - return gulp.src(globLangs(testedLangs()), { read: false }).pipe( + return gulp.src(globLang(testedLang()), { read: false }).pipe( through2.obj(function obj(file, enc, next) { lintMarkdown(file, next); }) @@ -41,8 +41,8 @@ const defaultTask = gulp.series(generateCurriculum, watchFiles); * Helper functions **/ -function globLangs(langs) { - return langs.map(lang => `./challenges/${lang}/**/*.md`); +function globLang(lang) { + return `./challenges/${lang}/**/*.md`; } gulp.task('default', defaultTask); diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index dbf5783db2..027e3cf75b 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -46,7 +46,7 @@ const { const { dasherize } = require('../../utils/slugs'); -const { testedLangs } = require('../utils'); +const { testedLang } = require('../utils'); const { buildDOMChallenge, @@ -124,22 +124,15 @@ async function setup() { global.Worker = createPseudoWorker(await newPageContext(browser)); page = await newPageContext(browser); await page.setViewport({ width: 300, height: 150 }); - const testLangs = testedLangs(); - if (testLangs.length > 1) - throw Error( - `Testing more than one language at once is not currently supported -please change the TEST_CHALLENGES_FOR_LANGS env variable to a single language` - ); - const challengesForLang = await Promise.all( - testLangs.map(lang => getChallenges(lang)) - ); + + const lang = testedLang(); + + let challenges = await getChallenges(lang); // the next few statements create a list of all blocks and superblocks // as they appear in the list of challenges - const blocks = challengesForLang[0].challenges.map(({ block }) => block); - const superBlocks = challengesForLang[0].challenges.map( - ({ superBlock }) => superBlock - ); + const blocks = challenges.map(({ block }) => block); + const superBlocks = challenges.map(({ superBlock }) => superBlock); const targetBlockStrings = [...new Set(blocks)]; const targetSuperBlockStrings = [...new Set(superBlocks)]; @@ -151,11 +144,11 @@ please change the TEST_CHALLENGES_FOR_LANGS env variable to a single language` ).bestMatch.target; console.log(`\nsuperBlock being tested: ${filter}`); - challengesForLang[0].challenges = challengesForLang[0].challenges.filter( + challenges = challenges.filter( challenge => challenge.superBlock === filter ); - if (!challengesForLang[0].challenges.length) { + if (!challenges.length) { throw new Error(`No challenges found with superBlock "${filter}"`); } } @@ -167,30 +160,26 @@ please change the TEST_CHALLENGES_FOR_LANGS env variable to a single language` ).bestMatch.target; console.log(`\nblock being tested: ${filter}`); - challengesForLang[0].challenges = challengesForLang[0].challenges.filter( - challenge => challenge.block === filter - ); + challenges = challenges.filter(challenge => challenge.block === filter); - if (!challengesForLang[0].challenges.length) { + if (!challenges.length) { throw new Error(`No challenges found with block "${filter}"`); } } const meta = {}; - for (const { lang, challenges } of challengesForLang) { - meta[lang] = {}; - for (const challenge of challenges) { - const dashedBlockName = dasherize(challenge.block); - if (!meta[dashedBlockName]) { - meta[lang][dashedBlockName] = (await getMetaForBlock( - dashedBlockName - )).challengeOrder; - } + for (const challenge of challenges) { + const dashedBlockName = dasherize(challenge.block); + if (!meta[dashedBlockName]) { + meta[dashedBlockName] = (await getMetaForBlock( + dashedBlockName + )).challengeOrder; } } return { meta, - challengesForLang + challenges, + lang }; } @@ -204,7 +193,7 @@ function cleanup() { spinner.stop(); } -function runTests({ challengesForLang, meta }) { +function runTests(challengeData) { // rethrow unhandled rejections to make sure the tests exit with -1 process.on('unhandledRejection', err => { throw err; @@ -214,9 +203,7 @@ function runTests({ challengesForLang, meta }) { after(function() { cleanup(); }); - for (const challenge of challengesForLang) { - populateTestsForLang(challenge, meta); - } + populateTestsForLang(challengeData); }); spinner.text = 'Testing'; run(); @@ -233,7 +220,7 @@ async function getChallenges(lang) { return [...challengeArray, ...flatten(challengesForBlock)]; }, []) ); - return { lang, challenges }; + return challenges; } function validateBlock(challenge) { @@ -245,7 +232,7 @@ function validateBlock(challenge) { } } -function populateTestsForLang({ lang, challenges }, meta) { +function populateTestsForLang({ lang, challenges, meta }) { const mongoIds = new MongoIds(); const challengeTitles = new ChallengeTitles(); const validateChallenge = challengeSchemaValidator(lang); @@ -257,7 +244,7 @@ function populateTestsForLang({ lang, challenges }, meta) { describe(challenge.block || 'No block', function() { describe(challenge.title || 'No title', function() { it('Matches a title in meta.json', function() { - const index = meta[lang][dashedBlockName].findIndex( + const index = meta[dashedBlockName].findIndex( arr => arr[1] === challenge.title ); @@ -269,7 +256,7 @@ function populateTestsForLang({ lang, challenges }, meta) { }); it('Matches an ID in meta.json', function() { - const index = meta[lang][dashedBlockName].findIndex( + const index = meta[dashedBlockName].findIndex( arr => arr[0] === challenge.id ); diff --git a/curriculum/utils.js b/curriculum/utils.js index c452b4ac84..cfd3b1b811 100644 --- a/curriculum/utils.js +++ b/curriculum/utils.js @@ -1,23 +1,18 @@ const path = require('path'); require('dotenv').config({ path: path.resolve(__dirname, '../.env') }); -const supportedLangs = [ - 'arabic', - 'chinese', - 'english', - 'portuguese', - 'russian', - 'spanish' -]; +const supportedLangs = ['chinese', 'english']; -exports.testedLangs = function testedLangs() { - if (process.env.TEST_CHALLENGES_FOR_LANGS) { - const filterLangs = process.env.TEST_CHALLENGES_FOR_LANGS.split(',').map( - lang => lang.trim().toLowerCase() - ); - return supportedLangs.filter(lang => filterLangs.includes(lang)); +exports.testedLang = function testedLang() { + if (process.env.LOCALE) { + if (supportedLangs.includes(process.env.LOCALE)) { + return process.env.LOCALE; + } else { + throw Error(`${process.env.LOCALE} is not a supported language. + Before the site can be built, this language needs to be manually approved`); + } } else { - return [...supportedLangs]; + throw Error('LOCALE must be set for testing'); } }; diff --git a/docs/how-to-work-on-coding-challenges.md b/docs/how-to-work-on-coding-challenges.md index c91558de73..d1f9707ddf 100644 --- a/docs/how-to-work-on-coding-challenges.md +++ b/docs/how-to-work-on-coding-challenges.md @@ -357,7 +357,7 @@ You are also able to test one challenge individually by performing the following Once you have verified that each challenge you've worked on passes the tests, [please create a pull request](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/how-to-open-a-pull-request.md). > [!TIP] -> You can set the environment variable `TEST_CHALLENGES_FOR_LANGS` in the `.env` to the language of the challenge(s) you need to test. +> You can set the environment variable `LOCALE` in the `.env` to the language of the challenge(s) you need to test. > > The currently accepted values are `english` and `chinese`, with `english` being set by default. diff --git a/docs/i18n-languages/polish/how-to-work-on-coding-challenges.md b/docs/i18n-languages/polish/how-to-work-on-coding-challenges.md index 9298a3c7c9..7cb2037e4c 100644 --- a/docs/i18n-languages/polish/how-to-work-on-coding-challenges.md +++ b/docs/i18n-languages/polish/how-to-work-on-coding-challenges.md @@ -311,7 +311,7 @@ function myFunc() { Przed utworzeniem [prośby o wyciągnięcie](how-to-open-a-pull-request.md) dla Twoich zmian, musisz sprawdzić, czy wprowadzone zmiany nie powodują nieumyślnie problemów z wyzwaniem. Aby przetestować wszystkie wyzwania, należy wykonać "test npm run test:curriculum". Aby zaoszczędzić czas możesz ograniczyć testy do jednego wyzwania wykonując następujące kroki: -1. W pliku `.env` ustaw zmienną środowiskową `TEST_CHALLENGES_FOR_LANGS` na język wyzwania (wyzwań), które musisz przetestować. Obecnie akceptowane wartości to `angielski`, `arabski`, `chiński`, `portugalski`, `rosyjski` i `hiszpański`. +1. W pliku `.env` ustaw zmienną środowiskową `LOCALE` na język wyzwania (wyzwań), które musisz przetestować. Obecnie akceptowane wartości to `angielski`, `arabski`, `chiński`, `portugalski`, `rosyjski` i `hiszpański`. 2. Przełączyć do katalogu `curriculum`: diff --git a/sample.env b/sample.env index b3625a09a2..bc88d48fe4 100644 --- a/sample.env +++ b/sample.env @@ -46,7 +46,6 @@ WEBHOOK_PROXY_URL='' LOCALE=english -TEST_CHALLENGES_FOR_LANGS=english DOCKER_HOST_LOCATION=localhost GHOST_CLIENT_KEY=123abc