Add err handling to test run

This commit is contained in:
Berkeley Martinez
2015-11-21 20:56:05 -08:00
parent 83ad2e14eb
commit d2be64cfb5

View File

@ -10,6 +10,7 @@ $(document).ready(function() {
common.editorKeyUp$ common.editorKeyUp$
.debounce(750) .debounce(750)
.map(() => common.editor.getValue()) .map(() => common.editor.getValue())
.distinctUntilChanged()
.doOnNext(() => console.log('updating value')) .doOnNext(() => console.log('updating value'))
.subscribe( .subscribe(
code => { code => {
@ -32,6 +33,9 @@ $(document).ready(function() {
common.updateOutputDisplay('' + output); common.updateOutputDisplay('' + output);
}, },
({ err }) => { ({ err }) => {
if (err.stack) {
console.error(err);
}
common.updateOutputDisplay('' + err); common.updateOutputDisplay('' + err);
} }
); );
@ -42,19 +46,28 @@ $(document).ready(function() {
) )
.flatMap(() => { .flatMap(() => {
common.appendToOutputDisplay('\n// testing challenge...'); common.appendToOutputDisplay('\n// testing challenge...');
return common.executeChallenge$(); return common.executeChallenge$()
}) .map(({ tests, ...rest }) => {
.map(({ tests, ...rest }) => { const solved = tests.every(test => !test.err);
const solved = tests.every(test => !test.err); return { ...rest, tests, solved };
return { ...rest, tests, solved }; })
.catch(err => Observable.just(err));
}) })
.subscribe( .subscribe(
({ solved, output, tests }) => { ({ err, solved, output, tests }) => {
if (err) {
console.error(err);
return common.updateOutputDisplay('' + err);
}
common.updateOutputDisplay(output); common.updateOutputDisplay(output);
common.displayTestResults(tests); common.displayTestResults(tests);
if (solved) { if (solved) {
common.showCompletion(); common.showCompletion();
} }
},
(err) => {
console.error(err);
common.updateOutputDisplay('' + err);
} }
); );