fix(learn): on user code execution error, run tests anyway
This commit is contained in:
@ -8,7 +8,7 @@ self.console.log = function proxyConsole(...args) {
|
|||||||
return oldLog(...args);
|
return oldLog(...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
onmessage = async e => {
|
self.onmessage = async e => {
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
const { code = '' } = e.data;
|
const { code = '' } = e.data;
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
@ -16,8 +16,22 @@ onmessage = async e => {
|
|||||||
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
||||||
/* eslint-enable no-unused-vars */
|
/* eslint-enable no-unused-vars */
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-eval
|
let testResult;
|
||||||
const testResult = eval(e.data.script);
|
let __userCodeWasExecuted = false;
|
||||||
|
/* eslint-disable no-eval */
|
||||||
|
try {
|
||||||
|
testResult = eval(`
|
||||||
|
${e.data.build}
|
||||||
|
__userCodeWasExecuted = true;
|
||||||
|
${e.data.testString}
|
||||||
|
`);
|
||||||
|
} catch (err) {
|
||||||
|
if (__userCodeWasExecuted) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
testResult = eval(e.data.testString);
|
||||||
|
}
|
||||||
|
/* eslint-enable no-eval */
|
||||||
if (typeof testResult === 'function') {
|
if (typeof testResult === 'function') {
|
||||||
await testResult(fileName => __toString(e.data.sources[fileName]));
|
await testResult(fileName => __toString(e.data.sources[fileName]));
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ function* executeJSChallengeSaga(proxyLogger) {
|
|||||||
return yield call(executeTests, async(testString, testTimeout) => {
|
return yield call(executeTests, async(testString, testTimeout) => {
|
||||||
try {
|
try {
|
||||||
return await testWorker.execute(
|
return await testWorker.execute(
|
||||||
{ script: build + '\n' + testString, code, sources },
|
{ build, testString, code, sources },
|
||||||
testTimeout
|
testTimeout
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -320,13 +320,12 @@ async function evaluateJsTest({ solution, files, test }) {
|
|||||||
|
|
||||||
const { build, sources } = await buildJSChallenge(files);
|
const { build, sources } = await buildJSChallenge(files);
|
||||||
const code = sources && 'index' in sources ? sources['index'] : '';
|
const code = sources && 'index' in sources ? sources['index'] : '';
|
||||||
const script = build + '\n' + test.testString;
|
|
||||||
|
|
||||||
const testWorker = createWorker('test-evaluator');
|
const testWorker = createWorker('test-evaluator');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { pass, err } = await testWorker.execute(
|
const { pass, err } = await testWorker.execute(
|
||||||
{ script, code, sources },
|
{ testString: test.testString, build, code, sources },
|
||||||
5000
|
5000
|
||||||
);
|
);
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
|
Reference in New Issue
Block a user