From 63d0a2682fc7ac473ed6340f68e6f05273bc7c5e Mon Sep 17 00:00:00 2001 From: Valeriy Date: Sat, 22 Dec 2018 23:12:23 +0300 Subject: [PATCH] fix: remove unused vars from the test execution scope --- client/src/client/frame-runner.js | 26 +++++++------------ .../moving-forward-from-here.english.md | 2 +- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/client/src/client/frame-runner.js b/client/src/client/frame-runner.js index 5197384a77..6ae8776250 100644 --- a/client/src/client/frame-runner.js +++ b/client/src/client/frame-runner.js @@ -10,12 +10,13 @@ if (window.frameElement && window.frameElement.id === testId) { } function initTestFrame() { - const frameReady = document.__frameReady; - const source = document.__source; - const __getUserInput = document.__getUserInput || (x => x); + const code = (document.__source || '').slice(0); + if (!document.__getUserInput) { + document.__getUserInput = () => code; + } - // Fake Deep Equal dependency /* eslint-disable no-unused-vars */ + // Fake Deep Equal dependency const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b); // Hardcode Deep Freeze dependency @@ -35,34 +36,25 @@ function initTestFrame() { }; const assert = chai.assert; - const getUserInput = __getUserInput; + /* eslint-enable no-unused-vars */ if (document.Enzyme) { window.Enzyme = document.Enzyme; } document.__runTest = async function runTests(testString) { - /* eslint-disable no-unused-vars */ - const code = source.slice(0); - const editor = { - getValue() { - return source; - } - }; - /* eslint-disable no-unused-vars */ // uncomment the following line to inspect // the frame-runner as it runs tests // make sure the dev tools console is open // debugger; try { - /* eslint-disable no-eval */ // eval test string to actual JavaScript // This return can be a function // i.e. function() { assert(true, 'happy coding'); } + // eslint-disable-next-line no-eval const test = eval(testString); - /* eslint-enable no-eval */ if (typeof test === 'function') { - await test(getUserInput); + await test(document.__getUserInput); } return { pass: true }; } catch (err) { @@ -79,5 +71,5 @@ function initTestFrame() { }; // notify that the window methods are ready to run - frameReady(); + document.__frameReady(); } diff --git a/curriculum/challenges/english/03-front-end-libraries/react-and-redux/moving-forward-from-here.english.md b/curriculum/challenges/english/03-front-end-libraries/react-and-redux/moving-forward-from-here.english.md index fead8fdf7c..d05b214b3f 100644 --- a/curriculum/challenges/english/03-front-end-libraries/react-and-redux/moving-forward-from-here.english.md +++ b/curriculum/challenges/english/03-front-end-libraries/react-and-redux/moving-forward-from-here.english.md @@ -24,7 +24,7 @@ Log the message 'Now I know React and Redux!' to the console. ```yml tests: - text: The message Now I know React and Redux! should be logged to the console. - testString: assert(editor.getValue().includes('console.log("Now I know React and Redux!")') || editor.getValue().includes('console.log(\'Now I know React and Redux!\')'), 'The message Now I know React and Redux! should be logged to the console.'); + testString: getUserInput => assert(/console.log\(("|')Now I know React and Redux!\1\)/.test(getUserInput('index')), 'The message Now I know React and Redux! should be logged to the console.'); ```