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