Test evaluation complete, need to hook pre-submit
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
debug = require('debug')('freecc:cntr:bonfires'),
|
debug = require('debug')('freecc:cntr:bonfires'),
|
||||||
bonfire = require('./../models/bonfire');
|
bonfire = require('./../models/Bonfire');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bonfire controller
|
* Bonfire controller
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
var printCallback;
|
||||||
// sends the input to the plugin for evaluation
|
// sends the input to the plugin for evaluation
|
||||||
var submit = function(code) {
|
var submit = function(code,callback) {
|
||||||
|
printCallback = callback;
|
||||||
// postpone the evaluation until the plugin is initialized
|
// postpone the evaluation until the plugin is initialized
|
||||||
plugin.whenConnected(
|
plugin.whenConnected(
|
||||||
function() {
|
function() {
|
||||||
@ -16,12 +17,7 @@ var submit = function(code) {
|
|||||||
|
|
||||||
// puts the message on the terminal
|
// puts the message on the terminal
|
||||||
var print = function(cls, msg) {
|
var print = function(cls, msg) {
|
||||||
if (cls) {
|
printCallback(cls,msg);
|
||||||
codeOutput.setValue(msg);
|
|
||||||
} else {
|
|
||||||
codeOutput.setValue(msg.output);
|
|
||||||
console.log(msg.type);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -44,9 +40,9 @@ var disconnect = function() {
|
|||||||
var api = {
|
var api = {
|
||||||
output: function(data) {
|
output: function(data) {
|
||||||
endLoading();
|
endLoading();
|
||||||
print('input', data.input);
|
//print('input', data.input);
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
print('message', data.error);
|
print('Error', data);
|
||||||
} else {
|
} else {
|
||||||
print(null, data);
|
print(null, data);
|
||||||
}
|
}
|
||||||
|
@ -68,57 +68,124 @@ var doLinting = function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var assert = chai.assert;
|
||||||
$('#submitButton').on('click', function () {
|
$('#submitButton').on('click', function () {
|
||||||
$('#codeOutput').empty();
|
$('#codeOutput').empty();
|
||||||
var js = myCodeMirror.getValue();
|
var js = myCodeMirror.getValue();
|
||||||
submit(js);
|
js = scrapeTests(js);
|
||||||
|
submit(js, function(cls, message) {
|
||||||
|
if (cls) {
|
||||||
|
codeOutput.setValue(message.error);
|
||||||
|
runTests('Error', null);
|
||||||
|
} else {
|
||||||
|
codeOutput.setValue(message.output);
|
||||||
|
runTests(null, message, function() {
|
||||||
|
createTestDisplay();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var assert = chai.assert;
|
var tests;
|
||||||
var testResults = [];
|
var testSalt = Math.Random();
|
||||||
$('#runTests').on('click', function () {
|
var scrapeTests = function(js) {
|
||||||
clearTestOutput();
|
return js;
|
||||||
var testCaseList = [],
|
}
|
||||||
jsCode = myCodeMirror.getValue();
|
|
||||||
getTestSuite().each(function () {
|
var createTestDisplay = function() {
|
||||||
testCaseList.push([$(this).data("input"), $(this).data("output"), $(this)]);
|
tests.forEach(function(test) {
|
||||||
});
|
var testDoc = document.createElement("li");
|
||||||
testCaseList.forEach(function (input) {
|
$(testDoc)
|
||||||
var testCode = jsCode + "\n\n" + input[0] + ";";
|
.addClass('list-group-item')
|
||||||
//TODO use plugin for this with the rest as a callback?
|
.addClass('well')
|
||||||
var output = eval(testCode);
|
.addClass('well-sm')
|
||||||
testEquality(output, input);
|
.html(test.text);
|
||||||
});
|
if (failedTests.indexOf(test) > -1) {
|
||||||
// some timeout here?
|
$(testDoc)
|
||||||
if (testResults.length === testCaseList.length) {
|
.css("background-color", 'rgba(255,0,0,.2)')
|
||||||
var sum = testResults.reduce(function (a, b) {
|
.prependTo($('#testSuite'));
|
||||||
return a + b
|
} else {
|
||||||
});
|
$(testDoc)
|
||||||
prependTestOutput("======Testing========\n" + Math.round(100 * sum / testResults.length) + "% tests passed\n");
|
.css('background-color', 'rgba(0,255,0,.2)')
|
||||||
}
|
.appendTo($('#testSuite'));
|
||||||
});
|
|
||||||
var testEquality = function (output, input) {
|
|
||||||
try {
|
|
||||||
switch (typeof output) {
|
|
||||||
case 'object':
|
|
||||||
assert.deepEqual(output, input[1]);
|
|
||||||
break;
|
|
||||||
case 'string':
|
|
||||||
assert(output.localeCompare(input[1]));
|
|
||||||
break
|
|
||||||
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) {
|
var testWords = ['expect', 'should', 'assert'];
|
||||||
input[2].css("background-color", "rgba(255,0,0,.2)");
|
var failedTests = [];
|
||||||
appendTestOutput(createTestString(input[0], input[1]));
|
|
||||||
appendTestOutput("Test failed: \nOutput was: " + output + "\nType of output was: " + (typeof output));
|
var runTests = function(err, data, callback) {
|
||||||
testResults.push(0);
|
if (err && tests) {
|
||||||
|
tests = [{text: "No tests were run as the program returned an error"}];
|
||||||
|
createTestDisplay();
|
||||||
|
return;
|
||||||
|
} else if (tests) {
|
||||||
|
$('#testSuite').children().remove();
|
||||||
|
tests.forEach(function(test){
|
||||||
|
var testString = reassembleTest(test, data);
|
||||||
|
try {
|
||||||
|
var output = eval(testString);
|
||||||
|
} catch(err) {
|
||||||
|
failedTests.push(test);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var reassembleTest = function(test, data) {
|
||||||
|
var lineNum = test.line;
|
||||||
|
var regexp = new RegExp("\/\/" + lineNum + testSalt);
|
||||||
|
return data.input.replace(regexp, test.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// var assert = chai.assert;
|
||||||
|
// var testResults = [];
|
||||||
|
// $('#runTests').on('click', function () {
|
||||||
|
// clearTestOutput();
|
||||||
|
// var testCaseList = [],
|
||||||
|
// jsCode = myCodeMirror.getValue();
|
||||||
|
// getTestSuite().each(function () {
|
||||||
|
// testCaseList.push([$(this).data("input"), $(this).data("output"), $(this)]);
|
||||||
|
// });
|
||||||
|
// testCaseList.forEach(function (input) {
|
||||||
|
// var testCode = jsCode + "\n\n" + input[0] + ";";
|
||||||
|
// //TODO use plugin for this with the rest as a callback?
|
||||||
|
// var output = eval(testCode);
|
||||||
|
// testEquality(output, input);
|
||||||
|
// });
|
||||||
|
// // 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");
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// var testEquality = function (output, input) {
|
||||||
|
// try {
|
||||||
|
// switch (typeof output) {
|
||||||
|
// case 'object':
|
||||||
|
// assert.deepEqual(output, input[1]);
|
||||||
|
// break;
|
||||||
|
// case 'string':
|
||||||
|
// assert(output.localeCompare(input[1]));
|
||||||
|
// break
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
//$('#sideBySide').on('click', function () {
|
//$('#sideBySide').on('click', function () {
|
||||||
// var main = $('#mainEditorPanel');
|
// var main = $('#mainEditorPanel');
|
||||||
// if (main.hasClass('col-md-12')) {
|
// if (main.hasClass('col-md-12')) {
|
||||||
@ -214,57 +281,57 @@ var writeToTest = function (msg, location) {
|
|||||||
// m = re.exec(code);
|
// m = re.exec(code);
|
||||||
// }
|
// }
|
||||||
//};
|
//};
|
||||||
$('#testFunctionName').on('change', function () {
|
// $('#testFunctionName').on('change', function () {
|
||||||
$('#testInputs').children().remove();
|
// $('#testInputs').children().remove();
|
||||||
$('#testOutputs').children().remove();
|
// $('#testOutputs').children().remove();
|
||||||
var args = $('#testFunctionName option:selected').data("args");
|
// var args = $('#testFunctionName option:selected').data("args");
|
||||||
var argArray = args.split(",");
|
// var argArray = args.split(",");
|
||||||
argArray.forEach(function (arg) {
|
// argArray.forEach(function (arg) {
|
||||||
if (arg.length > 0) {
|
// if (arg.length > 0) {
|
||||||
createInputField('#testInputs', arg);
|
// createInputField('#testInputs', arg);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
createInputField('#testOutputs', 'Expected output');
|
// createInputField('#testOutputs', 'Expected output');
|
||||||
});
|
// });
|
||||||
var createInputField = function (className, arg) {
|
// var createInputField = function (className, arg) {
|
||||||
var inputDiv = document.createElement('div');
|
// var inputDiv = document.createElement('div');
|
||||||
$(inputDiv)
|
// $(inputDiv)
|
||||||
.addClass("control-group")
|
// .addClass("control-group")
|
||||||
.appendTo($(className));
|
// .appendTo($(className));
|
||||||
var inputLabel = document.createElement('label');
|
// var inputLabel = document.createElement('label');
|
||||||
$(inputLabel)
|
// $(inputLabel)
|
||||||
.attr("for", "inputs")
|
// .attr("for", "inputs")
|
||||||
.html(arg)
|
// .html(arg)
|
||||||
.addClass("col-xs-4 control-label")
|
// .addClass("col-xs-4 control-label")
|
||||||
.appendTo($(inputDiv));
|
// .appendTo($(inputDiv));
|
||||||
var textDiv = document.createElement('div');
|
// var textDiv = document.createElement('div');
|
||||||
$(textDiv)
|
// $(textDiv)
|
||||||
.addClass("col-xs-8 controls")
|
// .addClass("col-xs-8 controls")
|
||||||
.appendTo($(inputDiv));
|
// .appendTo($(inputDiv));
|
||||||
var inputArea = document.createElement('input');
|
// var inputArea = document.createElement('input');
|
||||||
$(inputArea)
|
// $(inputArea)
|
||||||
.attr("type", "text")
|
// .attr("type", "text")
|
||||||
.addClass("form-control")
|
// .addClass("form-control")
|
||||||
.appendTo($(inputDiv));
|
// .appendTo($(inputDiv));
|
||||||
$(document.createElement("br")).appendTo($(textDiv));
|
// $(document.createElement("br")).appendTo($(textDiv));
|
||||||
};
|
// };
|
||||||
$('#testFunctionName').on('focus', function () {
|
// $('#testFunctionName').on('focus', function () {
|
||||||
$('#testFunctionName').children().remove();
|
// $('#testFunctionName').children().remove();
|
||||||
var blankOpt = document.createElement("option");
|
// var blankOpt = document.createElement("option");
|
||||||
$(blankOpt).addClass("selected").appendTo($('#testFunctionName'));
|
// $(blankOpt).addClass("selected").appendTo($('#testFunctionName'));
|
||||||
var re = /function\s+(\w+)\s*\(([\w\s,]*)\)/g;
|
// var re = /function\s+(\w+)\s*\(([\w\s,]*)\)/g;
|
||||||
var code = myCodeMirror.getValue();
|
// var code = myCodeMirror.getValue();
|
||||||
createOptions(re, code);
|
// createOptions(re, code);
|
||||||
re = /var (\w+)\s*=\s*function\s*\(([\s\w,]*)\)/g;
|
// re = /var (\w+)\s*=\s*function\s*\(([\s\w,]*)\)/g;
|
||||||
createOptions(re, code);
|
// createOptions(re, code);
|
||||||
});
|
// });
|
||||||
$('#hideTestCreate').on('click', function () {
|
// $('#hideTestCreate').on('click', function () {
|
||||||
var testForm = $("#testCreateForm");
|
// var testForm = $("#testCreateForm");
|
||||||
if (testForm.is(":visible")) {
|
// if (testForm.is(":visible")) {
|
||||||
testForm.hide();
|
// testForm.hide();
|
||||||
$(this).text("Create more tests");
|
// $(this).text("Create more tests");
|
||||||
} else {
|
// } else {
|
||||||
testForm.show();
|
// testForm.show();
|
||||||
$(this).text("Hide test creation dialogue")
|
// $(this).text("Hide test creation dialogue")
|
||||||
}
|
// }
|
||||||
});
|
// });
|
@ -28,16 +28,14 @@ block content
|
|||||||
.panel.panel-primary.panel-bonfire
|
.panel.panel-primary.panel-bonfire
|
||||||
.panel-heading.text-center Output
|
.panel-heading.text-center Output
|
||||||
.panel.panel-body
|
.panel.panel-body
|
||||||
ul#testSuite.list-group
|
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
|
||||||
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
|
|
||||||
form#testCreateForm.form-horizontal
|
|
||||||
br
|
br
|
||||||
form.code
|
form.code
|
||||||
.form-group.codeMirrorView
|
.form-group.codeMirrorView
|
||||||
textarea#codeOutput
|
textarea#codeOutput
|
||||||
|
br
|
||||||
|
ul#testSuite.list-group
|
||||||
|
|
||||||
#testInputs.form-group
|
|
||||||
#testOutputs.form-group
|
|
||||||
br
|
br
|
||||||
|
|
||||||
script(src='/js/lib/bonfire/framework.js')
|
script(src='/js/lib/bonfire/framework.js')
|
||||||
|
Reference in New Issue
Block a user