mirror of
https://github.com/zaphar/test-tap.git
synced 2025-07-21 20:19:49 -04:00
fixes for IE contributed by mike from the joose project
git-svn-id: https://test-tap.googlecode.com/svn/trunk@4 62346678-a08d-11dd-9c66-c9f8973bfffa
This commit is contained in:
parent
eab18fe7dd
commit
c389566659
@ -97,15 +97,19 @@ Test.TAP.prototype.todo = function(func) {
|
|||||||
self.mk_tap = tapper;
|
self.mk_tap = tapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
Test.TAP.prototype.skip = function(crit, reason, func) {
|
Test.TAP.prototype.skip = function(crit, reason, count, func) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (crit) {
|
if (crit) {
|
||||||
var tapper = self.mk_tap;
|
var tapper = self.mk_tap;
|
||||||
self.mk_tap = function(ok, desc) {
|
self.mk_tap = function(ok, desc) {
|
||||||
tapper.apply(self, [ok, "# SKIP: "+reason]);
|
tapper.apply(self, [ok, desc]);
|
||||||
|
}
|
||||||
|
for(var i = 0; i < count; i++) {
|
||||||
|
self.fail("# SKIP "+reason)
|
||||||
}
|
}
|
||||||
func();
|
|
||||||
self.mk_tap = tapper;
|
self.mk_tap = tapper;
|
||||||
|
} else {
|
||||||
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +205,11 @@ Tests that a string matches the regex.
|
|||||||
|
|
||||||
Test.TAP.prototype.like = function(string, regex, desc) {
|
Test.TAP.prototype.like = function(string, regex, desc) {
|
||||||
this._pass_if(function(){
|
this._pass_if(function(){
|
||||||
return string.match(regex);
|
if(regex instanceof RegExp) {
|
||||||
|
return string.match(regex)
|
||||||
|
} else {
|
||||||
|
return string.indexOf(regex) != -1
|
||||||
|
}
|
||||||
}, desc)
|
}, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ Test.TAP.Class.prototype.run_it = function(method) {
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Delete globals which were created during test execution
|
// Delete globals which were created during test execution
|
||||||
// THis avoid conflicts between tests when running multiple tests in a r
|
// THis avoid conflicts between tests when running multiple tests in a row
|
||||||
for(var name in top) {
|
for(var name in top) {
|
||||||
if(!originalGlobal[name]) {
|
if(!originalGlobal[name]) {
|
||||||
delete top[name]
|
delete top[name]
|
||||||
@ -149,33 +149,41 @@ Test.TAP.Class.prototype.run_tests = function() {
|
|||||||
}
|
}
|
||||||
var run = function () {
|
var run = function () {
|
||||||
if(self.finished) {
|
if(self.finished) {
|
||||||
|
console.log('methods = '+methods+' length: '+methods.length+' Interval: '+testRunInterval);
|
||||||
|
//console.log('count = '+count+' Interval: '+testRunInterval);
|
||||||
if(count > 0) {
|
if(count > 0) {
|
||||||
if(self.on_finished) {
|
if(self.on_finished) {
|
||||||
onFinish()
|
onFinish()
|
||||||
self.on_finished()
|
self.on_finished()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('made it past count test for interval: '+testRunInterval);
|
||||||
if(methods.length == 0) {
|
if(methods.length == 0) {
|
||||||
|
console.log('clearing interval: '+testRunInterval);
|
||||||
clearInterval(testRunInterval)
|
clearInterval(testRunInterval)
|
||||||
if(self.on_finished_all) {
|
if(self.on_finished_all) {
|
||||||
self.on_finished_all()
|
self.on_finished_all()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.log('we are finished but methods is not long enough interval: '+testRunInterval);
|
||||||
self.finished = false;
|
self.finished = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(self.planned == "no_plan" || self.planned == 0 || self.counter >= self.planned) {
|
if(self.planned == "no_plan"
|
||||||
|
|| self.planned == 0
|
||||||
|
|| self.counter >= self.planned) {
|
||||||
self.finished = true
|
self.finished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
testRunInterval = setInterval(run, 10)
|
testRunInterval = setInterval(run, 50)
|
||||||
run();
|
run();
|
||||||
var methodname;
|
var methodname;
|
||||||
while (methodname = methods.shift()) {
|
while (methodname = methods.shift()) {
|
||||||
self.run_it(methodname);
|
self.run_it(methodname);
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
run();
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
@ -1,39 +1,69 @@
|
|||||||
function load(path) {
|
Test.TAPBrowser = function (path, tests) {
|
||||||
var url = location.pathname + "#" + encodeURIComponent(path.replace(/^\.\//, ''))
|
this.test_path = path;
|
||||||
|
|
||||||
|
this.parseLocation()
|
||||||
|
|
||||||
|
if(this.params.test) {
|
||||||
|
this.tests = [this.params.test];
|
||||||
|
} else {
|
||||||
|
this.tests = tests
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.params.real_world) {
|
||||||
|
var world = new Test.RealWorld()
|
||||||
|
world[this.params.real_world]()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Test.TAPBrowser.prototype = {
|
||||||
|
|
||||||
|
parseLocation: function () {
|
||||||
|
var info = {};
|
||||||
|
var hash = new String(location.hash)
|
||||||
|
if(hash.length > 1) {
|
||||||
|
var parts = hash.substr(1).split(";")
|
||||||
|
for(var i = 0; i < parts.length; i++) {
|
||||||
|
var pair = parts[i].split("=");
|
||||||
|
info[pair[0]] = pair[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.params = info;
|
||||||
|
},
|
||||||
|
|
||||||
|
loadTest: function (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>...');
|
Test.TAP.prototype.diag('loading: '+path+' <a href="'+url+'">(run in a single window)</a>...');
|
||||||
|
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open("GET", path, false);
|
req.open("GET", path, false);
|
||||||
req.send(null);
|
req.send(null);
|
||||||
|
|
||||||
|
// TODO is this AJAX Impl. robust enough?
|
||||||
if (req.readyState == 4) {
|
if (req.readyState == 4) {
|
||||||
var testobj = eval(req.responseText);
|
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;
|
return testobj;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
function createScriptTag(library) {
|
createPath: function (t) {
|
||||||
var path = library.replace(/\./g, '/')+'.js';
|
var path = this.test_path +'/'+t;
|
||||||
var script = document.createElement("script");
|
return path
|
||||||
script.src = lib+'/'+path;
|
},
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadlib(library) {
|
runTest: function (t) {
|
||||||
document.body.appendChild(createScriptTag(library));
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadTest(test) {
|
|
||||||
var path = testlib+'/'+test;
|
|
||||||
return load(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadComponents() {
|
|
||||||
for (c in toLoad) {
|
|
||||||
var comp = toLoad[c];
|
|
||||||
loadlib(comp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runtest(t) {
|
|
||||||
var outtxt = "";
|
var outtxt = "";
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
|
|
||||||
@ -60,7 +90,7 @@ function runtest(t) {
|
|||||||
|
|
||||||
// set globally for synchronous run
|
// set globally for synchronous run
|
||||||
Test.TAP.prototype.out = outfunc;
|
Test.TAP.prototype.out = outfunc;
|
||||||
var testobj = loadTest(t);
|
var testobj = this.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");
|
||||||
@ -75,25 +105,20 @@ function runtest(t) {
|
|||||||
} else {
|
} else {
|
||||||
div.className += ' pass';
|
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
var out = "nothing yet";
|
var out = "nothing yet";
|
||||||
var diag = "";
|
var diag = "";
|
||||||
var t = new Test.TAP.Class(); // the real TAP
|
var t = new Test.TAP.Class(); // the real TAP
|
||||||
//t.plan('no_plan');
|
|
||||||
t.plan(27);
|
t.plan(27);
|
||||||
//t.plan());
|
|
||||||
|
|
||||||
t.testCan = function () {
|
t.testCan = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -133,6 +131,7 @@ t.testPass = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.testPlan = function() {
|
t.testPlan = function() {
|
||||||
|
var self = this;
|
||||||
// setup fake test object
|
// setup fake test object
|
||||||
var f = new Test.TAP(); // the TAP that's failing
|
var f = new Test.TAP(); // the TAP that's failing
|
||||||
f.out = function(newout) { out = newout };
|
f.out = function(newout) { out = newout };
|
||||||
@ -140,11 +139,11 @@ t.testPlan = function() {
|
|||||||
|
|
||||||
// begin real tests!
|
// begin real tests!
|
||||||
f.ok(false, 'false fails');
|
f.ok(false, 'false fails');
|
||||||
this.is(f.counter, 1, 'counter increments by one');
|
self.is(f.counter, 1, 'counter increments by one');
|
||||||
this.is(f.planned, 2, 'planned = 2');
|
self.is(f.planned, 2, 'planned = 2');
|
||||||
}
|
}
|
||||||
|
|
||||||
t.testTodo = function() {
|
t.testTodoSkip = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var out;
|
var out;
|
||||||
self.can_ok(Test.TAP, 'todo', 'skip');
|
self.can_ok(Test.TAP, 'todo', 'skip');
|
||||||
@ -154,23 +153,23 @@ t.testTodo = function() {
|
|||||||
|
|
||||||
f.todo(function() {
|
f.todo(function() {
|
||||||
f.ok(true, 'true is true');
|
f.ok(true, 'true is true');
|
||||||
|
});
|
||||||
self.like(out, /ok 1 - # TODO: true is true/g,
|
self.like(out, /ok 1 - # TODO: true is true/g,
|
||||||
'the non todo output is suitably formatted');
|
'the non todo output is suitably formatted');
|
||||||
});
|
|
||||||
f.ok(!false, 'not false is true');
|
f.ok(!false, 'not false is true');
|
||||||
self.like(out, /ok 2 -/g, 'the regular output is suitably formatted');
|
self.like(out, /ok 2 -/g, 'the regular output is suitably formatted');
|
||||||
|
|
||||||
f.skip(true, 'because I said so',
|
f.skip(true, 'because I said so', 1,
|
||||||
function() {
|
function() {
|
||||||
f.is(1, 2, 'one is two');
|
f.is(1, 2, 'one is two');
|
||||||
self.like(out, /^not ok 3 - # SKIP: because I said so$/,
|
|
||||||
'the skipped output is suitably formatted');
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
self.like(out, /^not ok 3 - # SKIP because I said so$/,
|
||||||
|
'the skipped output is suitably formatted');
|
||||||
f.is(1, 1, 'one is one');
|
f.is(1, 1, 'one is one');
|
||||||
self.like(out, /ok 4 - one is one/,
|
self.like(out, /ok 4 - one is one/,
|
||||||
'the non skipped output is suitable formatted');
|
'the non skipped output is suitable formatted');
|
||||||
}
|
};
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
})()
|
})()
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<script type="text/javascript" src="../lib/Test/TAP.js"></script>
|
<script type="text/javascript" src="../lib/Test/TAP.js"></script>
|
||||||
|
<script type="text/javascript" src="../lib/Test/TAP/Runner.js"></script>
|
||||||
<script type="text/javascript" src="../lib/Test/TAP/Class.js"></script>
|
<script type="text/javascript" src="../lib/Test/TAP/Class.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -33,20 +34,22 @@
|
|||||||
/** Configuration options
|
/** Configuration options
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
var toLoad = [];
|
|
||||||
var tests = [
|
var tests = [
|
||||||
'01_tap.t.js',
|
'01_tap.t.js',
|
||||||
];
|
];
|
||||||
var lib = '../lib';
|
|
||||||
var testlib = '.';
|
var testlib = '.';
|
||||||
|
|
||||||
/** Setup
|
/** Setup
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
var loc = String(top.location);
|
|
||||||
var results = [];
|
|
||||||
</script>
|
</script>
|
||||||
This is the Test.TAP.Class and company test harness for the browser.
|
This is the Test.TAP.Class and company test harness for the browser.
|
||||||
<script type="text/javascript" src="../lib/Test/TAPBrowser.js"></script>
|
<script type="text/javascript" src="../lib/Test/TAPBrowser.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.onload = function() {
|
||||||
|
var browser = new Test.TAPBrowser(testlib, tests);
|
||||||
|
browser.run();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -34,15 +34,9 @@
|
|||||||
/** Configuration options
|
/** Configuration options
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
var toLoad = [
|
|
||||||
'<list project libraries here>',
|
|
||||||
];
|
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
'<list test files here>',
|
'<list test files here>',
|
||||||
];
|
];
|
||||||
// Change this to your javascript library location
|
|
||||||
var lib = '../lib';
|
|
||||||
// Change this to the path of your test scripts
|
// Change this to the path of your test scripts
|
||||||
var testlib = '.';
|
var testlib = '.';
|
||||||
|
|
||||||
@ -53,5 +47,11 @@
|
|||||||
var results = [];
|
var results = [];
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="../ext/Test/TAPBrowser.js"></script>
|
<script type="text/javascript" src="../ext/Test/TAPBrowser.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.onload = function() {
|
||||||
|
var browser = new Test.TAPBrowser(".", tests);
|
||||||
|
browser.run();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user