Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hacked to use new QUnit.log params, include browser version, fix tests

  • Loading branch information...
commit 151406c124684311cf677b99250cf29184179afd 1 parent 398e3c2
Benjamin Lee authored
Showing with 121 additions and 14 deletions.
  1. +19 −0 index.html
  2. +4 −0 myLib.js
  3. +22 −6 myLibTest.js
  4. +76 −8 suite.js
19 index.html
View
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <link rel="stylesheet" href="../qunit/qunit/qunit.css" type="text/css"/>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"> </script>
+ <script type="text/javascript" src="../qunit/qunit/qunit.js"></script>
+ <script type="text/javascript" src="myLib.js"></script>
+ <script type="text/javascript" src="myLibTest.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">QUnit example</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture">test markup, will be hidden</div>
+</body>
+</html>
4 myLib.js
View
@@ -1,3 +1,7 @@
function newAddition(x, y) {
return x + y;
+}
+
+function newSubtraction(x, y) {
+ return x - y - y; // bug!
}
28 myLibTest.js
View
@@ -1,6 +1,22 @@
-test("Adding numbers works", function() {
- expect(3);
- ok(newAddition, "function exists");
- equals(4, newAddition(2, 2), "2 + 2 = 4");
- equals(100, newAddition(100, 0), "zero is zero");
-});
+var myLibTests = function() {
+
+ test("Adding numbers", function() {
+ expect(3);
+ ok(newAddition, "function exists");
+ equals(newAddition(2, 2), 4, "2 + 2 = 4");
+ equals(newAddition(100, 0), 100, "zero is zero");
+ });
+
+ test("Subtracting numbers", function() {
+ expect(2);
+ ok(newSubtraction, "subtraction function exists");
+ equals(newSubtraction(2, 2), 0, "2 - 2 = 0");
+ });
+};
+
+if(typeof document !== "undefined" && typeof jQuery !== "undefined") {
+ jQuery(myLibTests);
+}
+else {
+ myLibTests();
+}
84 suite.js
View
@@ -1,13 +1,81 @@
load("../qunit/qunit/qunit.js");
-QUnit.init();
-QUnit.config.blocking = false;
-QUnit.config.autorun = true;
-QUnit.config.updateRate = 0;
-
-QUnit.log = function(result, message, details) {
- print(result ? 'PASS' : 'FAIL', details.message);
-};
+(function() {
+ QUnit.init();
+ QUnit.config.blocking = false;
+ QUnit.config.autorun = true;
+ QUnit.config.updateRate = 0;
+
+ var stop_watch = {
+ start_time: null, stop_time: null,
+
+ start: function() {
+ this.start_time = new Date();
+ },
+
+ stop: function() {
+ this.stop_time = new Date();
+ },
+
+ elapsed_seconds: function() {
+ return ( this.stop_time.getMilliseconds() - this.start_time.getMilliseconds() ) / 1000;
+ }
+ };
+
+ var current_test_name = null;
+ var current_test_assertions = [];
+ var totals = { pass: 0, fail: 0};
+
+ QUnit.testStart = function(name) {
+ current_test_name = name;
+ };
+
+ QUnit.testDone = function(name, fail_count, total_count) {
+ if(fail_count > 0) {
+ print("FAIL - " + name);
+
+ for(var i = 0; i < current_test_assertions.length; i++) {
+ print(" " + current_test_assertions[i]);
+ }
+
+
+ totals.fail = totals.fail + 1;
+ }
+ else {
+ print("PASS - " + name);
+ totals.pass = totals.pass + 1;
+ }
+ };
+
+ QUnit.log = function(result, message, details) {
+ details.message = details.message || "";
+
+ var type = (typeof details.expected !== "undefined") ? "EQ" : "OK";
+
+ var outcome = result ? "PASS" : "FAIL";
+
+ var response = "";
+ if(!result && typeof details.expected !== "undefined") {
+ response = "Expected: " + details.expected + ", Actual: " + details.actual;
+ }
+
+ current_test_assertions.push([outcome, type, details.message, response].join("|"));
+ };
+
+ // executing twice per test?
+ QUnit.done = function() {
+ stop_watch.stop();
+
+ print("----------------------------------------");
+ print(" PASS: " + totals.pass + " FAIL: " + totals.fail + " TOTAL: " + (totals.pass + totals.fail));
+ print(" Finished in " + stop_watch.elapsed_seconds() + " seconds.");
+ print("----------------------------------------");
+ };
+
+ stop_watch.start(); // hacked b/c QUnit.begin only executes in a browser env on dom ready
+})();
+
+
load("myLib.js");
load("myLibTest.js");
Please sign in to comment.
Something went wrong with that request. Please try again.