Configurating Console.log
This commit is contained in:
@ -45,6 +45,11 @@ var api = {
|
|||||||
} else {
|
} else {
|
||||||
print('output', data.output);
|
print('output', data.output);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
console: {
|
||||||
|
log: function(msg) {
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -48,28 +48,10 @@ block content
|
|||||||
.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,17 +127,9 @@ 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");
|
// some timeout here?
|
||||||
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) {
|
if (testResults.length === testCaseList.length) {
|
||||||
var sum = testResults.reduce(function (a, b) {
|
var sum = testResults.reduce(function (a, b) {
|
||||||
return a + b
|
return a + b
|
||||||
@ -163,26 +137,43 @@ block content
|
|||||||
prependTestOutput("======Testing========\n" + Math.round(100 * sum / testResults.length) + "% tests passed\n");
|
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) {
|
||||||
|
try {
|
||||||
switch (typeof output) {
|
switch (typeof output) {
|
||||||
case 'object':
|
case 'object':
|
||||||
assert.deepEqual(output, input);
|
assert.deepEqual(output, input[1]);
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
assert(output.localeCompare(input));
|
assert(output.localeCompare(input[1]));
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
assert.equal(output, input);
|
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)
|
||||||
|
Reference in New Issue
Block a user