mirror of
https://github.com/zaphar/test-tap.git
synced 2025-07-21 20:19:49 -04:00
made the test harness a little easier to read
git-svn-id: https://test-tap.googlecode.com/svn/trunk@8 62346678-a08d-11dd-9c66-c9f8973bfffa
This commit is contained in:
parent
9337bc047e
commit
90966cab7d
@ -1,75 +1,39 @@
|
|||||||
Test.TAPBrowser = function (path, tests) {
|
function load(path) {
|
||||||
this.test_path = path;
|
var url = location.pathname + "#" + encodeURIComponent(path.replace(/^\.\//, ''))
|
||||||
|
Test.TAP.prototype.diag('loading: '+path+' <a href="'+url+'">(run in a single window)</a>...');
|
||||||
this.parseLocation()
|
var req = new XMLHttpRequest();
|
||||||
|
req.open("GET", path, false);
|
||||||
if(this.params.test) {
|
req.send(null);
|
||||||
this.tests = [this.params.test];
|
if (req.readyState == 4) {
|
||||||
} else {
|
var testobj = eval(req.responseText);
|
||||||
this.tests = tests
|
return testobj;
|
||||||
}
|
|
||||||
|
|
||||||
if(this.params.real_world) {
|
|
||||||
var world = new Test.RealWorld()
|
|
||||||
world[this.params.real_world]()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Test.TAPBrowser.prototype = {
|
function createScriptTag(library) {
|
||||||
|
var path = library.replace(/\./g, '/')+'.js';
|
||||||
|
var script = document.createElement("script");
|
||||||
|
script.src = lib+'/'+path;
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
|
||||||
parseLocation: function () {
|
function loadlib(library) {
|
||||||
var info = {};
|
document.body.appendChild(createScriptTag(library));
|
||||||
var hash = new String(location.hash)
|
}
|
||||||
if(hash.length > 1) {
|
|
||||||
var parts = hash.substr(1).split(";")
|
function loadTest(test) {
|
||||||
for(var i = 0; i < parts.length; i++) {
|
var path = testlib+'/'+test;
|
||||||
var pair = parts[i].split("=");
|
return load(path);
|
||||||
info[pair[0]] = pair[1]
|
}
|
||||||
|
|
||||||
|
function loadComponents() {
|
||||||
|
for (c in toLoad) {
|
||||||
|
var comp = toLoad[c];
|
||||||
|
loadlib(comp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.params = info;
|
|
||||||
},
|
|
||||||
|
|
||||||
loadTest: function (t) {
|
function runtest(t) {
|
||||||
|
|
||||||
var path = this.createPath(t);
|
|
||||||
|
|
||||||
var url = location.pathname + "#test=" + encodeURIComponent(path.replace(/^\.\//, ''))
|
|
||||||
Test.TAP.prototype.diag('loading: '+path+' <a href="'+url+'">(run in a single window)</a>...');
|
|
||||||
|
|
||||||
var req;
|
|
||||||
if(navigator.appName == 'Microsoft Internet Explorer') {
|
|
||||||
req = new ActiveXObject("Microsoft.XMLHTTP");
|
|
||||||
} else {
|
|
||||||
req = new XMLHttpRequest();
|
|
||||||
}
|
|
||||||
if(!req) throw "Can't create XML HTTP Request Object"
|
|
||||||
req.open("GET", path, false);
|
|
||||||
req.send(null);
|
|
||||||
|
|
||||||
// TODO is this AJAX Impl. robust enough?
|
|
||||||
if (req.readyState == 4) {
|
|
||||||
if(window && window.console && console.log) {
|
|
||||||
console.log("Evaluating test file "+path)
|
|
||||||
}
|
|
||||||
var testobj;
|
|
||||||
try {
|
|
||||||
var js = req.responseText;
|
|
||||||
// TODO this needs to be added to every source file instead
|
|
||||||
testobj = eval(js);
|
|
||||||
} catch(e) {
|
|
||||||
throw(e)
|
|
||||||
}
|
|
||||||
return testobj;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
createPath: function (t) {
|
|
||||||
var path = this.test_path +'/'+t;
|
|
||||||
return path
|
|
||||||
},
|
|
||||||
|
|
||||||
runTest: function (t) {
|
|
||||||
var outtxt = "";
|
var outtxt = "";
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
|
|
||||||
@ -82,14 +46,7 @@ Test.TAPBrowser.prototype = {
|
|||||||
}
|
}
|
||||||
div.className = c;
|
div.className = c;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(div.addEventListener) {
|
|
||||||
div.addEventListener('click', onclick, true);
|
div.addEventListener('click', onclick, true);
|
||||||
} else if(div.attachEvent) {
|
|
||||||
div.attachEvent('onclick', onclick);
|
|
||||||
} else {
|
|
||||||
throw "Can't attach event without addEventListener or attachEvent";
|
|
||||||
}
|
|
||||||
|
|
||||||
div.className = 'test small';
|
div.className = 'test small';
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
@ -97,13 +54,18 @@ Test.TAPBrowser.prototype = {
|
|||||||
var outfunc = function(text) {
|
var outfunc = function(text) {
|
||||||
if (text) {
|
if (text) {
|
||||||
outtxt += text;
|
outtxt += text;
|
||||||
div.innerHTML = div.innerHTML + "\n" + text + "<br />"
|
if (text.match(/(not ok|Test Suite Crashed)/g) ) {
|
||||||
|
div.innerHTML = "<div class='fail'>" + div.innerHTML + "\n" + text + "</div>"
|
||||||
|
} else {
|
||||||
|
div.innerHTML = "<div class='pass'>" + div.innerHTML + "\n" + text + "</div>"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set globally for synchronous run
|
// set globally for synchronous run
|
||||||
Test.TAP.prototype.out = outfunc;
|
Test.TAP.prototype.out = outfunc;
|
||||||
var testobj = this.loadTest(t);
|
var testobj = loadTest(t);
|
||||||
if (!testobj) {
|
if (!testobj) {
|
||||||
alert ("Test Object: "+t+" did not load");
|
alert ("Test Object: "+t+" did not load");
|
||||||
throw new ReferenceError("Test Object did now load");
|
throw new ReferenceError("Test Object did now load");
|
||||||
@ -113,25 +75,29 @@ Test.TAPBrowser.prototype = {
|
|||||||
|
|
||||||
testobj.on_finished = function () {
|
testobj.on_finished = function () {
|
||||||
if (outtxt.match(/(not ok|Test Suite Crashed)/g) ) {
|
if (outtxt.match(/(not ok|Test Suite Crashed)/g) ) {
|
||||||
div.className += ' fail';
|
div.className += ' failsuite';
|
||||||
div.className.replace(/small/, 'big');
|
div.className.replace(/small/, 'big');
|
||||||
} else {
|
|
||||||
div.className += ' pass';
|
|
||||||
}
|
}
|
||||||
|
results.push(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
testobj.run_tests();
|
testobj.run_tests()
|
||||||
}, 0)
|
}, 0)
|
||||||
},
|
|
||||||
|
|
||||||
run: function () {
|
|
||||||
for (var i = 0; i < this.tests.length; i++) {
|
|
||||||
var t = this.tests[i]
|
|
||||||
this.runTest(t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var test = loc.match(/.+[#?](.*)\??.*/);
|
||||||
|
|
||||||
|
loadComponents();
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
var testlist = [];
|
||||||
|
if (test) {
|
||||||
|
runtest(test[1]);
|
||||||
|
} else {
|
||||||
|
for (t in tests) {
|
||||||
|
runtest(tests[t]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
.fail { background-color : red; }
|
.fail { background-color : red; }
|
||||||
.pass { background-color : green; }
|
.pass { background-color : green; }
|
||||||
|
.failsuite {border: 3px solid red;}
|
||||||
</style>
|
</style>
|
||||||
<!--Test Description here -->
|
<!--Test Description here -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user