Mercurial > browser-couch
changeset 6:25d079125b95
Changed display of test output to be more colorful and not require firebug.
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Fri, 10 Apr 2009 08:13:58 -0700 |
| parents | fdbad39a9170 |
| children | 4a0fe44529a8 |
| files | index.css index.html tests.js |
| diffstat | 3 files changed, 55 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/index.css Fri Apr 10 08:13:58 2009 -0700 @@ -0,0 +1,18 @@ +.test { +} + +.in-progress { + background-color: yellow; +} + +.successful { + background-color: lawnGreen; +} + +.failed { + background-color: red; +} + +.pending { + background-color: lightGrey; +}
--- a/index.html Fri Apr 10 07:47:39 2009 -0700 +++ b/index.html Fri Apr 10 08:13:58 2009 -0700 @@ -3,14 +3,44 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + <link rel="stylesheet" type="text/css" media="all" + href="index.css" /> <title>Browser Couch Tests</title> </head> <body> <h1>Browser Couch Tests</h1> +<div id="status"> +</div> </body> <script src="browser-couch.js"></script> <script src="tests.js"></script> <script> -Tests.run(); +var listener = { + onReady: function(tests) { + var status = document.getElementById("status"); + for (var i = 0; i < tests.length; i++) { + var test = tests[i]; + var div = document.createElement("div"); + div.className = "test pending"; + div.id = "test_" + test.id; + div.textContent = test.name + " pending"; + status.appendChild(div); + } + }, + onRun: function(test) { + var div = document.getElementById("test_" + test.id); + div.textContent = test.name + " running"; + div.className = "test in-progress"; + }, + onFinish: function(test) { + var div = document.getElementById("test_" + test.id); + div.textContent = test.name + " OK"; + div.className = "test successful"; + } +}; + +Tests.run(listener); </script> </html>
--- a/tests.js Fri Apr 10 07:47:39 2009 -0700 +++ b/tests.js Fri Apr 10 08:13:58 2009 -0700 @@ -1,13 +1,7 @@ var Tests = { - run: function(container, console, setTimeout) { + run: function(listener, container, setTimeout) { if (!container) container = this; - if (!console) { - if (!window.console) - throw new Error("window.console unavailable"); - else - console = window.console; - } if (!setTimeout) setTimeout = window.setTimeout; @@ -20,6 +14,7 @@ func: container[name], isAsync: name.indexOf("_async") != -1, console: console, + id: tests.length, assertEqual: function assertEqual(a, b) { if (a != b) throw new Error(a + " != " + b); @@ -28,22 +23,22 @@ tests.push(test); } + listener.onReady(tests); var nextTest = 0; function runNextTest() { if (nextTest < tests.length) { var test = tests[nextTest]; - console.log("Running " + test.name + "..."); + listener.onRun(test); test.done = function() { - console.log("OK"); + listener.onFinish(this); setTimeout(runNextTest, 0); }; test.func(test); if (!test.isAsync) test.done(); nextTest++; - } else - console.log("All tests passed."); + } } runNextTest();
