showJS view now shows errors in a pretty format (kinda)

This commit is contained in:
Nathan Leniz
2015-02-14 18:43:45 -05:00
parent 9ac19023d9
commit e3c9e42fce
2 changed files with 8 additions and 19 deletions

View File

@ -34,21 +34,6 @@ if (attempts) {
attempts = 0; attempts = 0;
} }
// Default value for editor if one isn't provided in (i.e. a challenge)
var nonChallengeValue = '/*Welcome to Bonfire, Free Code Camp\'s future CoderByte replacement.\n' +
'Please feel free to use Bonfire as an in-browser playground and linting tool.\n' +
'Note that you can also write tests using Chai.js by using the keywords assert and expect */\n\n' +
'function test() {\n' +
' assert(2 !== 3, "2 is not equal to 3");\n' +
' return [1,2,3].map(function(elem) {\n' +
' return elem * elem;\n' +
' });\n' +
'}\n' +
'expect(test()).to.be.a("array");\n\n' +
'assert.deepEqual(test(), [1,4,9]);\n\n' +
'var foo = test();\n' +
'foo.should.be.a("array");\n\n' +
'test();\n';
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), { var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
lineNumbers: false, lineNumbers: false,
@ -183,12 +168,13 @@ var createTestDisplay = function() {
var test = userTests[i]; var test = userTests[i];
var testDoc = document.createElement("div"); var testDoc = document.createElement("div");
if (test.err != null) { if (test.err != null) {
console.log('Should be displaying bad tests');
$(testDoc) $(testDoc)
.html("<div class='row'><div class='col-xs-1 text-center'><i class='ion-close-circled big-error-icon'></i></div><div class='col-xs-11 test-output wrappable'>" + test.text + "</div><div class='col-xs-11 test-output wrappable'>" + test.err + "</div></div><div class='ten-pixel-break'/>") .html("<div class='row'><div class='col-xs-2 text-center'><i class='ion-close-circled big-error-icon'></i></div><div class='col-xs-10 test-output wrappable'>" + test.text + "</div><div class='col-xs-10 test-output wrappable'>" + test.err + "</div></div><div class='ten-pixel-break'/>")
.prependTo($('#testSuite')) .prependTo($('#testSuite'))
} else { } else {
$(testDoc) $(testDoc)
.html("<div class='row'><div class='col-xs-1 text-center'><i class='ion-checkmark-circled big-success-icon'></i></div><div class='col-xs-11 test-output test-vertical-center wrappable'>" + test.text + "</div></div><div class='ten-pixel-break'/>") .html("<div class='row'><div class='col-xs-2 text-center'><i class='ion-checkmark-circled big-success-icon'></i></div><div class='col-xs-10 test-output test-vertical-center wrappable'>" + test.text + "</div></div><div class='ten-pixel-break'/>")
.appendTo($('#testSuite')); .appendTo($('#testSuite'));
} }
}; };
@ -220,8 +206,11 @@ var runTests = function(err, data) {
} }
} catch(error) { } catch(error) {
allTestsPassed = false; allTestsPassed = false;
console.log(error);
arr[ix].err = error.name + ":" + error.message; arr[ix].err = error.name + ":" + error.message;
} finally {
if (!test) {
createTestDisplay();
}
} }
}); });

View File

@ -42,7 +42,7 @@ block content
.form-group.codeMirrorView .form-group.codeMirrorView
textarea#codeOutput textarea#codeOutput
br br
#testSuite.hidden #testSuite
br br
script(type="text/javascript"). script(type="text/javascript").
var tests = !{JSON.stringify(tests)}; var tests = !{JSON.stringify(tests)};