fix: simplify language specific testing
Prevents multiple languages' challenges from being tested at once.
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
45e4a770a2
commit
7055211959
@ -4,7 +4,7 @@ const through2 = require('through2');
|
|||||||
|
|
||||||
const { locale } = require('../config/env.json');
|
const { locale } = require('../config/env.json');
|
||||||
const { getChallengesForLang } = require('./getChallenges');
|
const { getChallengesForLang } = require('./getChallenges');
|
||||||
const { testedLangs } = require('./utils');
|
const { testedLang } = require('./utils');
|
||||||
const lintMarkdown = require('../tools/scripts/lint');
|
const lintMarkdown = require('../tools/scripts/lint');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ function watchFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function lint() {
|
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) {
|
through2.obj(function obj(file, enc, next) {
|
||||||
lintMarkdown(file, next);
|
lintMarkdown(file, next);
|
||||||
})
|
})
|
||||||
@ -41,8 +41,8 @@ const defaultTask = gulp.series(generateCurriculum, watchFiles);
|
|||||||
* Helper functions
|
* Helper functions
|
||||||
**/
|
**/
|
||||||
|
|
||||||
function globLangs(langs) {
|
function globLang(lang) {
|
||||||
return langs.map(lang => `./challenges/${lang}/**/*.md`);
|
return `./challenges/${lang}/**/*.md`;
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('default', defaultTask);
|
gulp.task('default', defaultTask);
|
||||||
|
@ -46,7 +46,7 @@ const {
|
|||||||
|
|
||||||
const { dasherize } = require('../../utils/slugs');
|
const { dasherize } = require('../../utils/slugs');
|
||||||
|
|
||||||
const { testedLangs } = require('../utils');
|
const { testedLang } = require('../utils');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
buildDOMChallenge,
|
buildDOMChallenge,
|
||||||
@ -124,22 +124,15 @@ async function setup() {
|
|||||||
global.Worker = createPseudoWorker(await newPageContext(browser));
|
global.Worker = createPseudoWorker(await newPageContext(browser));
|
||||||
page = await newPageContext(browser);
|
page = await newPageContext(browser);
|
||||||
await page.setViewport({ width: 300, height: 150 });
|
await page.setViewport({ width: 300, height: 150 });
|
||||||
const testLangs = testedLangs();
|
|
||||||
if (testLangs.length > 1)
|
const lang = testedLang();
|
||||||
throw Error(
|
|
||||||
`Testing more than one language at once is not currently supported
|
let challenges = await getChallenges(lang);
|
||||||
please change the TEST_CHALLENGES_FOR_LANGS env variable to a single language`
|
|
||||||
);
|
|
||||||
const challengesForLang = await Promise.all(
|
|
||||||
testLangs.map(lang => getChallenges(lang))
|
|
||||||
);
|
|
||||||
|
|
||||||
// the next few statements create a list of all blocks and superblocks
|
// the next few statements create a list of all blocks and superblocks
|
||||||
// as they appear in the list of challenges
|
// as they appear in the list of challenges
|
||||||
const blocks = challengesForLang[0].challenges.map(({ block }) => block);
|
const blocks = challenges.map(({ block }) => block);
|
||||||
const superBlocks = challengesForLang[0].challenges.map(
|
const superBlocks = challenges.map(({ superBlock }) => superBlock);
|
||||||
({ superBlock }) => superBlock
|
|
||||||
);
|
|
||||||
const targetBlockStrings = [...new Set(blocks)];
|
const targetBlockStrings = [...new Set(blocks)];
|
||||||
const targetSuperBlockStrings = [...new Set(superBlocks)];
|
const targetSuperBlockStrings = [...new Set(superBlocks)];
|
||||||
|
|
||||||
@ -151,11 +144,11 @@ please change the TEST_CHALLENGES_FOR_LANGS env variable to a single language`
|
|||||||
).bestMatch.target;
|
).bestMatch.target;
|
||||||
|
|
||||||
console.log(`\nsuperBlock being tested: ${filter}`);
|
console.log(`\nsuperBlock being tested: ${filter}`);
|
||||||
challengesForLang[0].challenges = challengesForLang[0].challenges.filter(
|
challenges = challenges.filter(
|
||||||
challenge => challenge.superBlock === filter
|
challenge => challenge.superBlock === filter
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!challengesForLang[0].challenges.length) {
|
if (!challenges.length) {
|
||||||
throw new Error(`No challenges found with superBlock "${filter}"`);
|
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;
|
).bestMatch.target;
|
||||||
|
|
||||||
console.log(`\nblock being tested: ${filter}`);
|
console.log(`\nblock being tested: ${filter}`);
|
||||||
challengesForLang[0].challenges = challengesForLang[0].challenges.filter(
|
challenges = challenges.filter(challenge => challenge.block === filter);
|
||||||
challenge => challenge.block === filter
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!challengesForLang[0].challenges.length) {
|
if (!challenges.length) {
|
||||||
throw new Error(`No challenges found with block "${filter}"`);
|
throw new Error(`No challenges found with block "${filter}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta = {};
|
const meta = {};
|
||||||
for (const { lang, challenges } of challengesForLang) {
|
for (const challenge of challenges) {
|
||||||
meta[lang] = {};
|
const dashedBlockName = dasherize(challenge.block);
|
||||||
for (const challenge of challenges) {
|
if (!meta[dashedBlockName]) {
|
||||||
const dashedBlockName = dasherize(challenge.block);
|
meta[dashedBlockName] = (await getMetaForBlock(
|
||||||
if (!meta[dashedBlockName]) {
|
dashedBlockName
|
||||||
meta[lang][dashedBlockName] = (await getMetaForBlock(
|
)).challengeOrder;
|
||||||
dashedBlockName
|
|
||||||
)).challengeOrder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
meta,
|
meta,
|
||||||
challengesForLang
|
challenges,
|
||||||
|
lang
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +193,7 @@ function cleanup() {
|
|||||||
spinner.stop();
|
spinner.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
function runTests({ challengesForLang, meta }) {
|
function runTests(challengeData) {
|
||||||
// rethrow unhandled rejections to make sure the tests exit with -1
|
// rethrow unhandled rejections to make sure the tests exit with -1
|
||||||
process.on('unhandledRejection', err => {
|
process.on('unhandledRejection', err => {
|
||||||
throw err;
|
throw err;
|
||||||
@ -214,9 +203,7 @@ function runTests({ challengesForLang, meta }) {
|
|||||||
after(function() {
|
after(function() {
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
for (const challenge of challengesForLang) {
|
populateTestsForLang(challengeData);
|
||||||
populateTestsForLang(challenge, meta);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
spinner.text = 'Testing';
|
spinner.text = 'Testing';
|
||||||
run();
|
run();
|
||||||
@ -233,7 +220,7 @@ async function getChallenges(lang) {
|
|||||||
return [...challengeArray, ...flatten(challengesForBlock)];
|
return [...challengeArray, ...flatten(challengesForBlock)];
|
||||||
}, [])
|
}, [])
|
||||||
);
|
);
|
||||||
return { lang, challenges };
|
return challenges;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateBlock(challenge) {
|
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 mongoIds = new MongoIds();
|
||||||
const challengeTitles = new ChallengeTitles();
|
const challengeTitles = new ChallengeTitles();
|
||||||
const validateChallenge = challengeSchemaValidator(lang);
|
const validateChallenge = challengeSchemaValidator(lang);
|
||||||
@ -257,7 +244,7 @@ function populateTestsForLang({ lang, challenges }, meta) {
|
|||||||
describe(challenge.block || 'No block', function() {
|
describe(challenge.block || 'No block', function() {
|
||||||
describe(challenge.title || 'No title', function() {
|
describe(challenge.title || 'No title', function() {
|
||||||
it('Matches a title in meta.json', 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
|
arr => arr[1] === challenge.title
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -269,7 +256,7 @@ function populateTestsForLang({ lang, challenges }, meta) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Matches an ID in meta.json', function() {
|
it('Matches an ID in meta.json', function() {
|
||||||
const index = meta[lang][dashedBlockName].findIndex(
|
const index = meta[dashedBlockName].findIndex(
|
||||||
arr => arr[0] === challenge.id
|
arr => arr[0] === challenge.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,23 +1,18 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
|
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
|
||||||
|
|
||||||
const supportedLangs = [
|
const supportedLangs = ['chinese', 'english'];
|
||||||
'arabic',
|
|
||||||
'chinese',
|
|
||||||
'english',
|
|
||||||
'portuguese',
|
|
||||||
'russian',
|
|
||||||
'spanish'
|
|
||||||
];
|
|
||||||
|
|
||||||
exports.testedLangs = function testedLangs() {
|
exports.testedLang = function testedLang() {
|
||||||
if (process.env.TEST_CHALLENGES_FOR_LANGS) {
|
if (process.env.LOCALE) {
|
||||||
const filterLangs = process.env.TEST_CHALLENGES_FOR_LANGS.split(',').map(
|
if (supportedLangs.includes(process.env.LOCALE)) {
|
||||||
lang => lang.trim().toLowerCase()
|
return process.env.LOCALE;
|
||||||
);
|
} else {
|
||||||
return supportedLangs.filter(lang => filterLangs.includes(lang));
|
throw Error(`${process.env.LOCALE} is not a supported language.
|
||||||
|
Before the site can be built, this language needs to be manually approved`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return [...supportedLangs];
|
throw Error('LOCALE must be set for testing');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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).
|
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]
|
> [!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.
|
> The currently accepted values are `english` and `chinese`, with `english` being set by default.
|
||||||
|
|
||||||
|
@ -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:
|
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`:
|
2. Przełączyć do katalogu `curriculum`:
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ WEBHOOK_PROXY_URL=''
|
|||||||
|
|
||||||
LOCALE=english
|
LOCALE=english
|
||||||
|
|
||||||
TEST_CHALLENGES_FOR_LANGS=english
|
|
||||||
DOCKER_HOST_LOCATION=localhost
|
DOCKER_HOST_LOCATION=localhost
|
||||||
|
|
||||||
GHOST_CLIENT_KEY=123abc
|
GHOST_CLIENT_KEY=123abc
|
||||||
|
Reference in New Issue
Block a user