Fix(Challenges): get user code (#16187)

* fix(Challenges.): Prevent source from being overwritten

* fix(Challenges): Tests should use name

* fix(seed/react): Namespace tests for now
This commit is contained in:
Berkeley Martinez
2017-12-13 15:24:36 -08:00
committed by Quincy Larson
parent 375442d365
commit d3bbf27dab
5 changed files with 91 additions and 65 deletions

View File

@@ -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) {