Permalink
Browse files

Rewired results stream and refactored setUp/tearDown invocation. HTML…

… runner now using Google CDN to load jQuery.
  • Loading branch information...
atesgoral committed Jul 2, 2009
1 parent 0295bfa commit d36946ede5c01ba04711fbb4fe488c1450029363
View
@@ -14,6 +14,14 @@ jsUnity = (function () {
return str.replace(/\?/g, function () { return a.shift(); });
}
+ function bind(fn, scope) {
+ return fn
+ ? function () {
+ fn.apply(scope, arguments);
+ }
+ : empty;
+ }
+
function hash(v) {
if (v instanceof Object) {
var arr = [];
@@ -306,35 +314,48 @@ jsUnity = (function () {
};
var resultsStream = {
- begin: function (total, suiteName) {
- jsUnity.tap.write("TAP version 13");
- jsUnity.tap.write("# " + suiteName);
- jsUnity.tap.write("1.." + total);
-
- jsUnity.log.info("Running "
- + (suiteName || "unnamed test suite"));
- jsUnity.log.info(plural(total, "test") + " found");
- },
+ begin: empty,
+ pass: empty,
+ fail: empty,
+ end: empty
+ };
- pass: function (index, testName) {
- jsUnity.tap.write(fmt("ok ? - ?", index, testName));
- jsUnity.log.info("[PASSED] " + testName);
- },
+ function resultsBegin(total, suiteName) {
+ resultsStream.begin.apply(this, arguments);
+
+ tapStream.write("TAP version 13");
+ tapStream.write("# " + suiteName);
+ tapStream.write("1.." + total);
- fail: function (index, testName, message) {
- jsUnity.tap.write(fmt("not ok ? - ?", index, testName));
- jsUnity.tap.write(" ---");
- jsUnity.tap.write(" " + message);
- jsUnity.tap.write(" ...");
- jsUnity.log.info(fmt("[FAILED] ?: ?", testName, message));
- },
+ logStream.info("Running "
+ + (suiteName || "unnamed test suite"));
+ logStream.info(plural(total, "test") + " found");
+ }
- end: function (passed, failed, duration) {
- jsUnity.log.info(plural(passed, "test") + " passed");
- jsUnity.log.info(plural(failed, "test") + " failed");
- jsUnity.log.info(plural(duration, "millisecond") + " elapsed");
- }
- };
+ function resultsPass(index, testName) {
+ resultsStream.pass.apply(this, arguments);
+
+ tapStream.write(fmt("ok ? - ?", index, testName));
+ logStream.info("[PASSED] " + testName);
+ }
+
+ function resultsFail(index, testName, message) {
+ resultsStream.fail.apply(this, arguments);
+
+ tapStream.write(fmt("not ok ? - ?", index, testName));
+ tapStream.write(" ---");
+ tapStream.write(" " + message);
+ tapStream.write(" ...");
+ logStream.info(fmt("[FAILED] ?: ?", testName, message));
+ }
+
+ function resultsEnd(passed, failed, duration) {
+ resultsStream.end.apply(this, arguments);
+
+ logStream.info(plural(passed, "test") + " passed");
+ logStream.info(plural(failed, "test") + " failed");
+ logStream.info(plural(duration, "millisecond") + " elapsed");
+ }
return {
TestSuite: function (suiteName, scope) {
@@ -393,6 +414,10 @@ jsUnity = (function () {
}
},
+ step: function () {
+ //return runtime;
+ },
+
run: function () {
var results = new jsUnity.TestResults();
@@ -409,24 +434,19 @@ jsUnity = (function () {
var cnt = suite.tests.length;
- this.results.begin(cnt, suite.suiteName);
+ resultsBegin(cnt, suite.suiteName);
// when running multiple suites, report counts at end?
suiteNames.push(suite.suiteName);
results.total += cnt;
- function getFixtureUtil(fnName) {
- var fn = suite[fnName];
-
- return fn
- ? function (testName) {
- fn.call(suite.scope, testName);
- }
- : empty;
- }
+ var runtime = {
+ //suite: suite
+ };
- var setUp = getFixtureUtil("setUp");
- var tearDown = getFixtureUtil("tearDown");
+ for (var util in { "setUp": 1, "tearDown": 1 }) {
+ runtime[util] = bind(suite[util], suite.scope);
+ }
for (var j = 0; j < cnt; j++) {
var test = suite.tests[j];
@@ -438,21 +458,21 @@ jsUnity = (function () {
var tearDownCalled = false;
try {
- setUp(test.name);
- test.fn.call(suite.scope, test.name);
+ runtime.setUp(test.name);
+ bind(test.fn, suite.scope)(test.name);
tearDownCalled = true;
- tearDown(test.name);
+ runtime.tearDown(test.name);
- this.results.pass(j + 1, test.name);
+ resultsPass(j + 1, test.name);
results.passed++;
testOutcome.passed = true;
} catch (e) {
if (!tearDownCalled) {
- tearDown(test.name);
+ runtime.tearDown(test.name);
}
- this.results.fail(j + 1, test.name, e);
+ resultsFail(j + 1, test.name, e);
testOutcome.passed = false;
testOutcome.failureMessage = e;
@@ -467,7 +487,7 @@ jsUnity = (function () {
results.failed = results.total - results.passed;
results.duration = jsUnity.env.getDate() - start;
- this.results.end(results.passed, results.failed, results.duration);
+ resultsEnd(results.passed, results.failed, results.duration);
return results;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
+#tooltip {
+ position: absolute;
+ z-index: 3000;
+ border: 1px solid #111;
+ background-color: #eee;
+ padding: 5px;
+ opacity: 0.85;
+}
+#tooltip h3, #tooltip div { margin: 0; }

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<title>jsUnity HTML Runner</title>
+<link rel="stylesheet" type="text/css" href="jquery.tooltip.css">
+<link rel="stylesheet" type="text/css" href="style.css">
+<link rel="icon" type="image/gif" href="i/jsunity_square_16.gif">
+<script type="text/javascript" src="../../jsunity.js"></script>
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.2/jquery-ui.min.js"></script>
+<script type="text/javascript" src="jquery.tooltip.min.js"></script>
+<script type="text/javascript" src="runner.js"></script>
+</head>
+<body>
+<div id="message">
+ <span id="txt">Do you have JavaScript or CSS disabled? You need to enable at least JavaScript to be able run any JavaScript tests.</span>
+ <a href="#" class="hidden" id="close">Dismiss</a>
+</div>
+<div id="main">
+ <div id="header">
+ <h1 title="jsUnity"><span>jsUnity</span></h1>
+ <div id="tagline">HTML Runner v0.1</div>
+ </div>
+ <div id="dialog">
+ <div id="settings">
+ <div id="fields">
+ <div class="field mandatory">
+ <label for="testSuiteUrl" title="This field is mandatory">Test Suite URL</label>
+ <span class="input" title="The URL of the test suite or multiple test suites delimited by commas."><input type="text" id="testSuiteUrl" size="64"/></span>
+ </div>
+ <div class="field mandatory">
+ <label for="testSuiteName" title="This field is mandatory">Test Suite Name</label>
+ <span class="input" title="The name of the test suite or multiple test suites delimited by commas."><input type="text" id="testSuiteName" size="64"/></span>
+ </div>
+ <div class="field">
+ <label for="rawResultUrl">Raw Results URL</label>
+ <span class="input" title="Raw results will be posted to this URL."><input type="text" id="rawResultUrl" size="64"/></span>
+ </div>
+ <div class="field">
+ <label for="xmlResultUrl">XML Results URL</label>
+ <span class="input" title="XML results (in JUnit format) will be posted to this URL."><input type="text" id="xmlResultUrl" size="64"/></span>
+ </div>
+ <div class="field">
+ <label for="tapUrl">TAP URL</label>
+ <span class="input" title="TAP data will be posted to this URL."><input type="text" id="tapUrl" size="64"/></span>
+ </div>
+ <div class="field">
+ <label for="logUrl">Log URL</label>
+ <span class="input" title="Log data will be posted to this URL."><input type="text" id="logUrl" size="64"/></span>
+ </div>
+ </div>
+ <div id="options" class="field">
+ <label for="autoRun">Auto-Run</label>
+ <span class="input" title="When checked, the tests will start running automatically."><input type="checkbox" id="autoRun"/></span>
+ <span class="spacer">|</span>
+ <label for="logLevel">Log Level</label>
+ <span class="input" title="The log verbosity level for jsUnity."><select id="logLevel">
+ <option>error</option>
+ <option>warn</option>
+ <option selected>info</option>
+ <option>debug</option>
+ </select></span>
+ </div>
+ </div>
+ <div id="controls">
+ <button id="run">Run</button>
+ <button id="stop">Stop</button>
+ </div>
+ </div>
+ <div id="log"></div>
+</div>
+<div id="footer">
+ <ul>
+ <li>Silk icon set 1.3 by <a href="http://www.famfamfam.com/lab/icons/silk/">Mark James</a></li>
+ <li>jQuery Tooltip plugin 1.3 by <a href="http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/">Jörn Zaefferer</a></li>
+ </ul>
+</div>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit d36946e

Please sign in to comment.