diff --git a/client/frame-runner.js b/client/frame-runner.js index 19da925dff..3411a790a0 100644 --- a/client/frame-runner.js +++ b/client/frame-runner.js @@ -73,31 +73,18 @@ document.addEventListener('DOMContentLoaded', function() { /* eslint-enable no-eval */ if (typeof test === 'function') { - // we know that the test eval'ed to a function - // the function could expect a callback - // or it could return a promise/observable - // or it could still be sync - if (test.length === 1) { - // a function with length 0 means it expects 0 args - // We call it and store the result - // This result may be a promise or an observable or undefined - __result = test(getUserInput); - } else { - // if function takes arguments - // we expect it to be of the form - // function(cb) { /* ... */ } - // and callback has the following signature - // function(err) { /* ... */ } - __result = Rx.Observable.fromNodeCallback(test)(getUserInput); - } + // all async tests must return a promise or observable + // sync tests can return Any type + __result = test(getUserInput); if (helpers.isPromise(__result)) { // turn promise into an observable __result = Rx.Observable.fromPromise(__result); } - } else { - // test is not a function - // fill result with for compatibility + } + + if (!__result || typeof __result.subscribe !== 'function') { + // make sure result is an observable __result = Rx.Observable.of(null); } } catch (e) { diff --git a/common/app/routes/Challenges/rechallenge/transformers.js b/common/app/routes/Challenges/rechallenge/transformers.js index 34eed3a746..4f6ae3e64a 100644 --- a/common/app/routes/Challenges/rechallenge/transformers.js +++ b/common/app/routes/Challenges/rechallenge/transformers.js @@ -5,11 +5,7 @@ import presetEs2015 from 'babel-preset-es2015'; import presetReact from 'babel-preset-react'; import { Observable } from 'rx'; -import { - transformHeadTailAndContents, - setContent, - setExt -} from '../../../../utils/polyvinyl.js'; +import * as vinyl from '../../../../utils/polyvinyl.js'; import castToObservable from '../../../utils/cast-to-observable.js'; const babelOptions = { presets: [ presetEs2015, presetReact ] }; @@ -35,43 +31,47 @@ const testJS$JSX = _.overSome(isJS, _.matchesProperty('ext', 'jsx')); // to `window.__console.log` // this let's us tap into logging into the console. // currently we only do this to the main window and not the test window -export function proxyLoggerTransformer(file) { - return transformHeadTailAndContents( - (source) => ( +export const proxyLoggerTransformer = _.partial( + vinyl.transformHeadTailAndContents, + source => ( source.replace(console$logReg, (match, methodCall) => { return 'window.__console' + methodCall; - })), - file - ); -} + })), +); -export const addLoopProtect = _.cond([ +const addLoopProtect = _.partial( + vinyl.transformContents, + contents => { + /* eslint-disable import/no-unresolved */ + const loopProtect = require('loop-protect'); + /* eslint-enable import/no-unresolved */ + loopProtect.hit = loopProtectHit; + return loopProtect(contents); + } +); + +export const addLoopProtectHtmlJsJsx = _.cond([ [ - testHTMLJS, - function(file) { - const _contents = file.contents.toLowerCase(); - if (file.ext === 'html' && !_contents.indexOf('