From 43a4fa8cb03beb26c786655fd48c9b50aa300aa4 Mon Sep 17 00:00:00 2001 From: Steven Failla Date: Sun, 26 May 2019 17:00:12 -0400 Subject: [PATCH] fix(client): reset test results before execution (#36029) * fixed issue where tests should fail when code has error Signed-off-by: Stevo99 * fix(client): Initialize tests as failing in case of build errors * fix: Reset tests to initial state when build fails * fix: simplify expression --- .../Challenges/redux/execute-challenge-saga.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/src/templates/Challenges/redux/execute-challenge-saga.js b/client/src/templates/Challenges/redux/execute-challenge-saga.js index b6b7863b1f..246c256904 100644 --- a/client/src/templates/Challenges/redux/execute-challenge-saga.js +++ b/client/src/templates/Challenges/redux/execute-challenge-saga.js @@ -36,9 +36,16 @@ export function* executeChallengeSaga() { } const consoleProxy = yield channel(); + try { yield put(initLogs()); yield put(initConsole('// running tests')); + // reset tests to initial state + const tests = (yield select(challengeTestsSelector)).map( + ({ text, testString }) => ({ text, testString }) + ); + yield put(updateTests(tests)); + yield fork(logToConsole, consoleProxy); const proxyLogger = args => consoleProxy.put(args); @@ -51,7 +58,7 @@ export function* executeChallengeSaga() { proxyLogger, document ); - const testResults = yield executeTests(testRunner); + const testResults = yield executeTests(testRunner, tests); yield put(updateTests(testResults)); yield put(updateConsole('// tests completed')); @@ -79,9 +86,7 @@ function* buildChallengeData(challengeData) { } } -function* executeTests(testRunner) { - const tests = yield select(challengeTestsSelector); - const testTimeout = 5000; +function* executeTests(testRunner, tests, testTimeout = 5000) { const testResults = []; for (const { text, testString } of tests) { const newTest = { text, testString };