fix: remove unused vars from the test execution scope
This commit is contained in:
@ -10,12 +10,13 @@ if (window.frameElement && window.frameElement.id === testId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initTestFrame() {
|
function initTestFrame() {
|
||||||
const frameReady = document.__frameReady;
|
const code = (document.__source || '').slice(0);
|
||||||
const source = document.__source;
|
if (!document.__getUserInput) {
|
||||||
const __getUserInput = document.__getUserInput || (x => x);
|
document.__getUserInput = () => code;
|
||||||
|
}
|
||||||
|
|
||||||
// Fake Deep Equal dependency
|
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
|
// Fake Deep Equal dependency
|
||||||
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
||||||
|
|
||||||
// Hardcode Deep Freeze dependency
|
// Hardcode Deep Freeze dependency
|
||||||
@ -35,34 +36,25 @@ function initTestFrame() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
const getUserInput = __getUserInput;
|
/* eslint-enable no-unused-vars */
|
||||||
|
|
||||||
if (document.Enzyme) {
|
if (document.Enzyme) {
|
||||||
window.Enzyme = document.Enzyme;
|
window.Enzyme = document.Enzyme;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.__runTest = async function runTests(testString) {
|
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
|
// uncomment the following line to inspect
|
||||||
// the frame-runner as it runs tests
|
// the frame-runner as it runs tests
|
||||||
// make sure the dev tools console is open
|
// make sure the dev tools console is open
|
||||||
// debugger;
|
// debugger;
|
||||||
try {
|
try {
|
||||||
/* eslint-disable no-eval */
|
|
||||||
// eval test string to actual JavaScript
|
// eval test string to actual JavaScript
|
||||||
// This return can be a function
|
// This return can be a function
|
||||||
// i.e. function() { assert(true, 'happy coding'); }
|
// i.e. function() { assert(true, 'happy coding'); }
|
||||||
|
// eslint-disable-next-line no-eval
|
||||||
const test = eval(testString);
|
const test = eval(testString);
|
||||||
/* eslint-enable no-eval */
|
|
||||||
if (typeof test === 'function') {
|
if (typeof test === 'function') {
|
||||||
await test(getUserInput);
|
await test(document.__getUserInput);
|
||||||
}
|
}
|
||||||
return { pass: true };
|
return { pass: true };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -79,5 +71,5 @@ function initTestFrame() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// notify that the window methods are ready to run
|
// notify that the window methods are ready to run
|
||||||
frameReady();
|
document.__frameReady();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ Log the message <code>'Now I know React and Redux!'</code> to the console.
|
|||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: The message <code>Now I know React and Redux!</code> should be logged to the console.
|
- text: The message <code>Now I know React and Redux!</code> 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 <code>Now I know React and Redux!</code> should be logged to the console.');
|
testString: getUserInput => assert(/console.log\(("|')Now I know React and Redux!\1\)/.test(getUserInput('index')), 'The message <code>Now I know React and Redux!</code> should be logged to the console.');
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user