From 2466d66eb12e1f7e3f2ce2dba0f7828bfc62cbfd Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Fri, 27 May 2016 17:11:25 -0700 Subject: [PATCH] Challenge now display console.log in output window --- client/frame-runner.js | 15 +---- client/rechallenge/transformers.js | 5 +- client/sagas/execute-challenge-saga.js | 36 +++++++--- client/sagas/frame-saga.js | 65 +++++++++++++------ .../challenges/components/classic/Output.jsx | 11 ++-- .../components/classic/Side-Panel.jsx | 21 ++++-- common/app/routes/challenges/redux/actions.js | 7 +- common/app/routes/challenges/redux/reducer.js | 8 +++ common/app/routes/challenges/redux/types.js | 1 + common/app/routes/challenges/utils.js | 13 ++++ 10 files changed, 127 insertions(+), 55 deletions(-) diff --git a/client/frame-runner.js b/client/frame-runner.js index d12e88d47f..e6e038a248 100644 --- a/client/frame-runner.js +++ b/client/frame-runner.js @@ -16,7 +16,7 @@ document.addEventListener('DOMContentLoaded', function() { output = eval(source); /* eslint-enable no-eval */ } catch (e) { - output = e.message; + output = e.message + '\n' + e.stack; window.__err = e; } return output; @@ -68,17 +68,6 @@ document.addEventListener('DOMContentLoaded', function() { .toArray(); }; - // used when updating preview without running tests - document.__checkPreview$ = function checkPreview$(args) { - if (window.__err) { - return Rx.Observable.throw(window.__err); - } - return Rx.Observable.just(args); - }; - - // now that the runPreviewTest$ is defined - // we set the subject to true - // this will let the updatePreview - // script now that we are ready. + // notify that the window methods are ready to run frameReady.onNext(null); }); diff --git a/client/rechallenge/transformers.js b/client/rechallenge/transformers.js index 537729d899..932d4c1eb3 100644 --- a/client/rechallenge/transformers.js +++ b/client/rechallenge/transformers.js @@ -1,6 +1,8 @@ import { Observable } from 'rx'; import loopProtect from 'loop-protect'; +import { updateContents } from '../../common/utils/polyvinyl'; + loopProtect.hit = function hit(line) { var err = 'Error: Exiting potential infinite loop at line ' + line + @@ -16,8 +18,7 @@ const transformersForHtmlJS = { { name: 'add-loop-protect', transformer: function addLoopProtect(file) { - file.contents = loopProtect(file.contents); - return file; + return updateContents(loopProtect(file.contents), file); } } ] diff --git a/client/sagas/execute-challenge-saga.js b/client/sagas/execute-challenge-saga.js index 3ec206ce60..e315fe230a 100644 --- a/client/sagas/execute-challenge-saga.js +++ b/client/sagas/execute-challenge-saga.js @@ -7,7 +7,7 @@ import types from '../../common/app/routes/challenges/redux/types'; import { frameMain, frameTests, - frameOutput + initOutput } from '../../common/app/routes/challenges/redux/actions'; import { setExt, updateContents } from '../../common/utils/polyvinyl'; @@ -98,18 +98,36 @@ export default function executeChallengeSaga(action$, getState) { return Observable.combineLatest(head$, frameRunner$) .map(([ head, frameRunner ]) => { - return head + `${source}` + frameRunner; - }) - .map(build => ({ source, build })); + const body = ` + + + ${source} + + `; + return { + build: head + body + frameRunner, + source, + head + }; + }); }) .flatMap(payload => { - const actions = []; - actions.push(frameMain(payload)); - if (type !== types.updateMain) { + const actions = [ + frameMain(payload) + ]; + if (type === types.executeChallenge) { actions.push(frameTests(payload)); - actions.push(frameOutput(payload)); } return Observable.from(actions, null, null, Scheduler.default); - }); + }) + .startWith(( + type === types.executeChallenge ? + initOutput('// running test') : + null + )) + .catch(error => Observable.just({ + type: 'app.error', + error + })); }); } diff --git a/client/sagas/frame-saga.js b/client/sagas/frame-saga.js index 04fa3bd3bf..1650ac15e2 100644 --- a/client/sagas/frame-saga.js +++ b/client/sagas/frame-saga.js @@ -1,9 +1,9 @@ import Rx, { Observable, Subject } from 'rx'; -import tape from 'tape'; +import loopProtect from 'loop-protect'; import types from '../../common/app/routes/challenges/redux/types'; import { updateOutput -} from '../../common/app/routes/challenges/redux/types'; +} from '../../common/app/routes/challenges/redux/actions'; import { updateTests } from '../../common/app/routes/challenges/redux/actions'; @@ -11,7 +11,6 @@ import { // we use three different frames to make them all essentially pure functions const mainId = 'fcc-main-frame'; const testId = 'fcc-test-frame'; -const outputId = 'fcc-output-frame'; const createHeader = (id = mainId) => `