fix: pass proxyLogger to params
This commit is contained in:
		| @@ -39,24 +39,26 @@ const testWorker = new WorkerExecutor('test-evaluator'); | |||||||
| const testTimeout = 5000; | const testTimeout = 5000; | ||||||
|  |  | ||||||
| function* ExecuteChallengeSaga() { | function* ExecuteChallengeSaga() { | ||||||
|  |   const consoleProxy = yield channel(); | ||||||
|   try { |   try { | ||||||
|     const { js, bonfire, backend } = challengeTypes; |     const { js, bonfire, backend } = challengeTypes; | ||||||
|     const { challengeType } = yield select(challengeMetaSelector); |     const { challengeType } = yield select(challengeMetaSelector); | ||||||
|  |  | ||||||
|     yield put(initLogs()); |     yield put(initLogs()); | ||||||
|     yield put(initConsole('// running tests')); |     yield put(initConsole('// running tests')); | ||||||
|  |     yield fork(logToConsole, consoleProxy); | ||||||
|  |  | ||||||
|     let testResults; |     let testResults; | ||||||
|     switch (challengeType) { |     switch (challengeType) { | ||||||
|       case js: |       case js: | ||||||
|       case bonfire: |       case bonfire: | ||||||
|         testResults = yield ExecuteJSChallengeSaga(); |         testResults = yield ExecuteJSChallengeSaga(consoleProxy); | ||||||
|         break; |         break; | ||||||
|       case backend: |       case backend: | ||||||
|         testResults = yield ExecuteBackendChallengeSaga(); |         testResults = yield ExecuteBackendChallengeSaga(consoleProxy); | ||||||
|         break; |         break; | ||||||
|       default: |       default: | ||||||
|         testResults = yield ExecuteDOMChallengeSaga(); |         testResults = yield ExecuteDOMChallengeSaga(consoleProxy); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     yield put(updateTests(testResults)); |     yield put(updateTests(testResults)); | ||||||
| @@ -64,6 +66,8 @@ function* ExecuteChallengeSaga() { | |||||||
|     yield put(logsToConsole('// console output')); |     yield put(logsToConsole('// console output')); | ||||||
|   } catch (e) { |   } catch (e) { | ||||||
|     yield put(updateConsole(e)); |     yield put(updateConsole(e)); | ||||||
|  |   } finally { | ||||||
|  |     consoleProxy.close(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -73,16 +77,15 @@ function* logToConsole(channel) { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function* ExecuteJSChallengeSaga() { | function* ExecuteJSChallengeSaga(proxyLogger) { | ||||||
|   const files = yield select(challengeFilesSelector); |   const files = yield select(challengeFilesSelector); | ||||||
|   const { code, solution } = yield call(buildJSFromFiles, files); |   const { code, solution } = yield call(buildJSFromFiles, files); | ||||||
|  |  | ||||||
|   const consoleProxy = yield channel(); |   const log = args => proxyLogger.put(args); | ||||||
|   yield fork(logToConsole, consoleProxy); |  | ||||||
|   const log = args => consoleProxy.put(args); |  | ||||||
|   testWorker.on('LOG', log); |   testWorker.on('LOG', log); | ||||||
|  |  | ||||||
|   const testResults = yield call(executeTests, (testString, testTimeout) => |   try { | ||||||
|  |     return yield call(executeTests, (testString, testTimeout) => | ||||||
|       testWorker |       testWorker | ||||||
|         .execute({ script: solution + '\n' + testString, code }, testTimeout) |         .execute({ script: solution + '\n' + testString, code }, testTimeout) | ||||||
|         .then(result => { |         .then(result => { | ||||||
| @@ -90,10 +93,9 @@ function* ExecuteJSChallengeSaga() { | |||||||
|           return result; |           return result; | ||||||
|         }) |         }) | ||||||
|     ); |     ); | ||||||
|  |   } finally { | ||||||
|     testWorker.remove('LOG', log); |     testWorker.remove('LOG', log); | ||||||
|   consoleProxy.close(); |   } | ||||||
|   return testResults; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function createTestFrame(state, ctx, proxyLogger) { | function createTestFrame(state, ctx, proxyLogger) { | ||||||
| @@ -103,17 +105,15 @@ function createTestFrame(state, ctx, proxyLogger) { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function* ExecuteDOMChallengeSaga() { | function* ExecuteDOMChallengeSaga(proxyLogger) { | ||||||
|   const state = yield select(); |   const state = yield select(); | ||||||
|   const ctx = yield call(buildHtmlFromFiles, state); |   const ctx = yield call(buildHtmlFromFiles, state); | ||||||
|   const consoleProxy = yield channel(); |  | ||||||
|   yield fork(logToConsole, consoleProxy); |  | ||||||
|  |  | ||||||
|   yield call(createTestFrame, state, ctx, consoleProxy); |   yield call(createTestFrame, state, ctx, proxyLogger); | ||||||
|   // wait for a code execution on a "ready" event in jQuery challenges |   // wait for a code execution on a "ready" event in jQuery challenges | ||||||
|   yield delay(100); |   yield delay(100); | ||||||
|  |  | ||||||
|   const testResults = yield call(executeTests, (testString, testTimeout) => |   return yield call(executeTests, (testString, testTimeout) => | ||||||
|     Promise.race([ |     Promise.race([ | ||||||
|       runTestInTestFrame(document, testString), |       runTestInTestFrame(document, testString), | ||||||
|       new Promise((_, reject) => |       new Promise((_, reject) => | ||||||
| @@ -121,20 +121,16 @@ function* ExecuteDOMChallengeSaga() { | |||||||
|       ) |       ) | ||||||
|     ]) |     ]) | ||||||
|   ); |   ); | ||||||
|  |  | ||||||
|   consoleProxy.close(); |  | ||||||
|   return testResults; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // TODO: use a web worker | // TODO: use a web worker | ||||||
| function* ExecuteBackendChallengeSaga() { | function* ExecuteBackendChallengeSaga(proxyLogger) { | ||||||
|   const state = yield select(); |   const state = yield select(); | ||||||
|   const ctx = yield call(buildBackendChallenge, state); |   const ctx = yield call(buildBackendChallenge, state); | ||||||
|   const consoleProxy = yield channel(); |  | ||||||
|  |  | ||||||
|   yield call(createTestFrame, state, ctx, consoleProxy); |   yield call(createTestFrame, state, ctx, proxyLogger); | ||||||
|  |  | ||||||
|   const testResults = yield call(executeTests, (testString, testTimeout) => |   return yield call(executeTests, (testString, testTimeout) => | ||||||
|     Promise.race([ |     Promise.race([ | ||||||
|       runTestInTestFrame(document, testString), |       runTestInTestFrame(document, testString), | ||||||
|       new Promise((_, reject) => |       new Promise((_, reject) => | ||||||
| @@ -142,9 +138,6 @@ function* ExecuteBackendChallengeSaga() { | |||||||
|       ) |       ) | ||||||
|     ]) |     ]) | ||||||
|   ); |   ); | ||||||
|  |  | ||||||
|   consoleProxy.close(); |  | ||||||
|   return testResults; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function* executeTests(testRunner) { | function* executeTests(testRunner) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user