Configurating Console.log

This commit is contained in:
Nathan Leniz
2015-01-20 00:36:14 -05:00
parent 4755bfcb56
commit cc3fa8e5f7
3 changed files with 50 additions and 56 deletions

View File

@ -45,6 +45,11 @@ var api = {
} else { } else {
print('output', data.output); print('output', data.output);
} }
},
console: {
log: function(msg) {
console.log(msg);
}
} }
}; };

View File

@ -42,8 +42,6 @@ var runHidden = function(code) {
var onoffline = null; var onoffline = null;
var ononline = null; var ononline = null;
var importScripts = null; var importScripts = null;
var console = null;
var application = null;
return eval(code); return eval(code);
} }

View File

@ -47,29 +47,11 @@ block content
.panel-heading Test Suite .panel-heading Test Suite
.panel.panel-body .panel.panel-body
ul#testSuite.list-group ul#testSuite.list-group
br br
#runTests.btn.btn-primary.btn-big.btn-block Run my test suite
#runTests.btn.btn-primary.btn-big.btn-block Run my test suite
textarea#testOutput textarea#testOutput
//#hintButton.btn.btn-info.btn-big.btn-block Show me hints
script. script.
//Button for moving test window to side
$('#sideBySide').on('click', function () {
var main = $('#mainEditorPanel');
if (main.hasClass('col-md-12')) {
replaceColClz(main, 'md', 12, 6);
replaceColClz(main, 'sm', 12, 6);
$(this).text("Original Layout")
} else {
replaceColClz(main, 'md', 6, 12);
replaceColClz(main, 'sm', 6, 12);
$(this).text("Tests side by side")
}
});
//Replace a bootstrap column number by browser size
var replaceColClz = function (elt, size, oldVal, newVal) {
elt.removeClass('col-' + size + '-' + oldVal);
elt.addClass('col-' + size + '-' + newVal);
};
var widgets = []; var widgets = [];
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor"), { var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor"), {
lineNumbers: true, lineNumbers: true,
@ -133,10 +115,10 @@ block content
submit(js); submit(js);
}); });
var assert = chai.assert; var assert = chai.assert;
var testResults = [];
$('#runTests').on('click', function () { $('#runTests').on('click', function () {
clearTestOutput(); clearTestOutput();
var testCaseList = [], var testCaseList = [],
testResults = [],
jsCode = myCodeMirror.getValue(); jsCode = myCodeMirror.getValue();
getTestSuite().each(function () { getTestSuite().each(function () {
testCaseList.push([$(this).data("input"), $(this).data("output"), $(this)]); testCaseList.push([$(this).data("input"), $(this).data("output"), $(this)]);
@ -145,44 +127,53 @@ block content
var testCode = jsCode + "\n\n" + input[0] + ";"; var testCode = jsCode + "\n\n" + input[0] + ";";
//TODO use plugin for this with the rest as a callback? //TODO use plugin for this with the rest as a callback?
var output = eval(testCode); var output = eval(testCode);
try { testEquality(output, input);
testEquality(output, input[1]);
appendTestOutput("\n" + createTestString(input[0], input[1]) + "\nTest passed!\n");
setTestBackground(input[2], "passed");
testResults.push(1);
} catch (err) {
setTestBackground(input[2], "failed");
appendTestOutput(createTestString(input[0], input[1]));
appendTestOutput("Test failed: \nOutput was: " + output + "\nType of output was: " + (typeof output));
testResults.push(0);
}
if (testResults.length === testCaseList.length) {
var sum = testResults.reduce(function (a, b) {
return a + b
});
prependTestOutput("======Testing========\n" + Math.round(100 * sum / testResults.length) + "% tests passed\n");
}
}); });
// some timeout here?
if (testResults.length === testCaseList.length) {
var sum = testResults.reduce(function (a, b) {
return a + b
});
prependTestOutput("======Testing========\n" + Math.round(100 * sum / testResults.length) + "% tests passed\n");
}
}); });
//After looking at chai assert, this is the way to go if you don't know the type
var testEquality = function (output, input) { var testEquality = function (output, input) {
switch (typeof output) { try {
case 'object': switch (typeof output) {
assert.deepEqual(output, input); case 'object':
break; assert.deepEqual(output, input[1]);
case 'string': break;
assert(output.localeCompare(input)); case 'string':
break assert(output.localeCompare(input[1]));
default: break
assert.equal(output, input); default:
assert.equal(output, input[1]);
}
appendTestOutput("\n" + createTestString(input[0], input[1]) + "\nTest passed!\n");
input[2].css("background-color", "rgba(0,255,0,.2)");
testResults.push(1);
} catch (err) {
input[2].css("background-color", "rgba(255,0,0,.2)");
appendTestOutput(createTestString(input[0], input[1]));
appendTestOutput("Test failed: \nOutput was: " + output + "\nType of output was: " + (typeof output));
testResults.push(0);
} }
}; };
var setTestBackground = function (elt, result) { $('#sideBySide').on('click', function () {
if (result.localeCompare('failed')) { var main = $('#mainEditorPanel');
elt.css("background-color", "rgba(255,0,0,.2)"); if (main.hasClass('col-md-12')) {
replaceColClz(main, 'md', 12, 6);
replaceColClz(main, 'sm', 12, 6);
$(this).text("Original Layout")
} else { } else {
elt.css("background-color", "rgba(0,255,0,.2)"); replaceColClz(main, 'md', 6, 12);
replaceColClz(main, 'sm', 6, 12);
$(this).text("Tests side by side")
} }
});
var replaceColClz = function (elt, size, oldVal, newVal) {
elt.removeClass('col-' + size + '-' + oldVal);
elt.addClass('col-' + size + '-' + newVal);
}; };
var getTestSuite = function () { var getTestSuite = function () {
return $('#testSuite').find('li'); return $('#testSuite').find('li');
@ -252,7 +243,7 @@ block content
var m = re.exec(code); var m = re.exec(code);
while (m != null) { while (m != null) {
var functionName = m[1]; var functionName = m[1];
if (functionName !== undefined && currentState.length === 0) { if (functionName !== undefined) {
var option = document.createElement('option'); var option = document.createElement('option');
$(option) $(option)
.html(functionName) .html(functionName)