test(curriculum): check challenges for all langs
This commit is contained in:
@ -25,25 +25,26 @@ const ChallengeTitles = require('./utils/challengeTitles');
|
|||||||
const { challengeSchemaValidator } = require('../schema/challengeSchema');
|
const { challengeSchemaValidator } = require('../schema/challengeSchema');
|
||||||
const { challengeTypes } = require('../../client/utils/challengeTypes');
|
const { challengeTypes } = require('../../client/utils/challengeTypes');
|
||||||
|
|
||||||
|
const { supportedLangs } = require('../utils');
|
||||||
|
|
||||||
const { LOCALE: lang = 'english' } = process.env;
|
const { LOCALE: lang = 'english' } = process.env;
|
||||||
|
|
||||||
const oldRunnerFail = Mocha.Runner.prototype.fail;
|
const oldRunnerFail = Mocha.Runner.prototype.fail;
|
||||||
Mocha.Runner.prototype.fail = function(test, err) {
|
Mocha.Runner.prototype.fail = function(test, err) {
|
||||||
if (err.stack && err instanceof AssertionError) {
|
if (err instanceof AssertionError) {
|
||||||
const assertIndex = err.message.indexOf(': expected');
|
const errMessage = String(err.message || '');
|
||||||
|
const assertIndex = errMessage.indexOf(': expected');
|
||||||
if (assertIndex !== -1) {
|
if (assertIndex !== -1) {
|
||||||
err.message = err.message.slice(0, assertIndex);
|
err.message = errMessage.slice(0, assertIndex);
|
||||||
}
|
}
|
||||||
// Don't show stacktrace for assertion errors.
|
// Don't show stacktrace for assertion errors.
|
||||||
|
if (err.stack) {
|
||||||
delete err.stack;
|
delete err.stack;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return oldRunnerFail.call(this, test, err);
|
return oldRunnerFail.call(this, test, err);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mongoIds = new MongoIds();
|
|
||||||
const challengeTitles = new ChallengeTitles();
|
|
||||||
const validateChallenge = challengeSchemaValidator(lang);
|
|
||||||
|
|
||||||
const { JSDOM } = jsdom;
|
const { JSDOM } = jsdom;
|
||||||
|
|
||||||
const babelOptions = {
|
const babelOptions = {
|
||||||
@ -56,7 +57,15 @@ const jQueryScript = fs.readFileSync(
|
|||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
|
|
||||||
(async function() {
|
runTests();
|
||||||
|
|
||||||
|
async function runTests() {
|
||||||
|
await Promise.all(supportedLangs.map(lang => populateTestsForLang(lang)));
|
||||||
|
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function populateTestsForLang(lang) {
|
||||||
const allChallenges = await getChallengesForLang(lang).then(curriculum =>
|
const allChallenges = await getChallengesForLang(lang).then(curriculum =>
|
||||||
Object.keys(curriculum)
|
Object.keys(curriculum)
|
||||||
.map(key => curriculum[key].blocks)
|
.map(key => curriculum[key].blocks)
|
||||||
@ -68,7 +77,11 @@ const jQueryScript = fs.readFileSync(
|
|||||||
}, [])
|
}, [])
|
||||||
);
|
);
|
||||||
|
|
||||||
describe('Check challenges tests', async function() {
|
const mongoIds = new MongoIds();
|
||||||
|
const challengeTitles = new ChallengeTitles();
|
||||||
|
const validateChallenge = challengeSchemaValidator(lang);
|
||||||
|
|
||||||
|
describe(`Check challenges (${lang})`, async function() {
|
||||||
before(async function() {
|
before(async function() {
|
||||||
this.timeout(30000);
|
this.timeout(30000);
|
||||||
global.browser = await puppeteer.launch({ args: ['--no-sandbox'] });
|
global.browser = await puppeteer.launch({ args: ['--no-sandbox'] });
|
||||||
@ -88,8 +101,7 @@ const jQueryScript = fs.readFileSync(
|
|||||||
it('Common checks', function() {
|
it('Common checks', function() {
|
||||||
const result = validateChallenge(challenge);
|
const result = validateChallenge(challenge);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
console.log(result.value);
|
throw new AssertionError(result.error);
|
||||||
throw new Error(result.error);
|
|
||||||
}
|
}
|
||||||
const { id, title } = challenge;
|
const { id, title } = challenge;
|
||||||
mongoIds.check(id, title);
|
mongoIds.check(id, title);
|
||||||
@ -209,9 +221,7 @@ const jQueryScript = fs.readFileSync(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
run();
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Fake Deep Equal dependency
|
// Fake Deep Equal dependency
|
||||||
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
||||||
|
@ -6,5 +6,13 @@ exports.dasherize = function dasherize(name) {
|
|||||||
.replace(/\:/g, '');
|
.replace(/\:/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const supportedLangs = ['english', 'spanish'];
|
const supportedLangs = [
|
||||||
|
'arabic',
|
||||||
|
'chinese',
|
||||||
|
'english',
|
||||||
|
'portuguese',
|
||||||
|
'russian',
|
||||||
|
'spanish'
|
||||||
|
];
|
||||||
|
|
||||||
exports.supportedLangs = supportedLangs;
|
exports.supportedLangs = supportedLangs;
|
||||||
|
Reference in New Issue
Block a user