Skip to content

Commit

Permalink
feat(scripts): add testing for React/Redux challenges
Browse files Browse the repository at this point in the history
ISSUES CLOSED: freeCodeCamp#305
  • Loading branch information
ojeytonwilliams committed Sep 6, 2018
1 parent 322bf80 commit 3fc6029
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
3 changes: 0 additions & 3 deletions getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ module.exports = function getChallenges(challengesDir) {
'MDNlinks',
'null',
'rawSolutions',
'react',
'reactRedux',
'redux',
'type'
])
);
Expand Down
3 changes: 3 additions & 0 deletions schema/challengeSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const schema = Joi.object().keys({
isRequired: Joi.bool(),
name: Joi.string(),
order: Joi.number(),
react: Joi.bool(),
reactRedux: Joi.bool(),
redux: Joi.bool(),
required: Joi.array().items(
Joi.object().keys({
link: Joi.string(),
Expand Down
28 changes: 21 additions & 7 deletions test-challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import ChallengeTitles from './challengeTitles';
import addAssertsToTapTest from './addAssertsToTapTest';
import { validateChallenge } from './schema/challengeSchema';

// modern challengeType
const modern = 6;

let mongoIds = new MongoIds();
let challengeTitles = new ChallengeTitles();

Expand All @@ -27,7 +24,15 @@ function evaluateTest(
test,
tapTest
) {
// code and editor provide access to the original text of the solution, which
// is needed since the solution itself is likely to change during
// transpilation.
let code = solution;
const editor = {
getValue() {
return code;
}
};

/* NOTE: Provide dependencies for React/Redux challenges
* and configure testing environment
Expand Down Expand Up @@ -72,14 +77,15 @@ function evaluateTest(
head = transform(head, options).code;
solution = transform(solution, options).code;
tail = transform(tail, options).code;
test = transform(test, options).code;
test.testString = transform(test.testString, options).code;

const { JSDOM } = require('jsdom');
// Mock DOM document for ReactDOM.render method
const jsdom = new JSDOM(`<!doctype html>
<html>
<body>
<div id="challenge-node"></div>
<div id="root"/>
<div id="challenge-node"/>
</body>
</html>
`);
Expand All @@ -94,9 +100,18 @@ function evaluateTest(
/* eslint-enable no-unused-vars */
try {
(() => {
return eval(
// As async tests are removed by createTest (since tests are run in series
// and waiting the default of 5 seconds between each test could result in
// an unreasonably slow test suite) the following differs somewhat from
// learn/src/client/frame-runner.js
const testOrResult = eval(
head + '\n' + solution + '\n' + tail + '\n' + test.testString
);
if (typeof testOrResult === 'function') {
// The function returned is intended to evaluate the text of the
// solution, which code contains.
testOrResult(() => code);
}
})();
} catch (e) {
console.log(head + '\n' + solution + '\n' + tail + '\n' + test.testString);
Expand Down Expand Up @@ -202,7 +217,6 @@ Observable.from(getChallenges())
.flatMap(challengeSpec => {
return Observable.from(challengeSpec.challenges);
})
.filter(({ challengeType }) => challengeType !== modern)
.flatMap(challenge => {
return createTest(challenge);
})
Expand Down

0 comments on commit 3fc6029

Please sign in to comment.