Permalink
Browse files

including qunit test suite, w/ empty tests for the moment.

  • Loading branch information...
1 parent 9dc8ad5 commit dbbbe5d897f8bafd5d0375ea75986c63e61859ac @paulirish paulirish committed Jun 8, 2012
Showing with 158 additions and 0 deletions.
  1. +60 −0 test/index.html
  2. +98 −0 test/qunit-yeti-adaptor.js
View
@@ -0,0 +1,60 @@
+<!doctype html>
+<html>
+<head>
+ <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.5.0.css" type="text/css"/>
+ <style>
+ h1 label {display: none!important}
+ </style>
+ <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.5.0.js"></script>
+ <script src="qunit-yeti-adaptor.js"></script>
+ <script type="text/javascript">
+ module("module1", {
+ setup: function() {
+ this.foobar = true;
+ }
+ });
+
+ test("first test with setup", function() {
+ ok(this.foobar, "this.foobar is defined");
+ });
+
+ module("module2", {
+ setup: function() {
+ this.foobar = "setup";
+ },
+ teardown: function() {
+ this.foobar = "teardown";
+ }
+ });
+
+ test("test with setup and teardown", function() {
+ expect(2);
+ ok(this.foobar);
+ equal(this.foobar, "setup");
+ });
+
+ asyncTest("asynchronous test", function() {
+ var that = this;
+ setTimeout(function() {
+ start();
+ // Start have to be called in async function
+ // No matter where
+ equal(that.foobar, "setup");
+ }, 3000);
+ });
+
+ module("module3");
+
+ test("test with neither setup nor teardown", function() {
+ equal(typeof this.foobar, "undefined");
+ // this object is cleaned up each test
+ });
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">HTML5 Please test suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
@@ -0,0 +1,98 @@
+/*
+ * - BUNYIP - http://github.com/ryanseddon/bunyip
+ * Yeti QUnit adaptor, drop this in a test suite that will run through Yeti.
+ * See readme.md for specific instructions.
+ * MIT License - Copyright (c) 2012 Ryan Seddon
+ * http://github.com/ryanseddon/yeti-adpators
+*/
+
+var BUNYIP = BUNYIP || {};
+
+(function(win, undef){
+
+ var testsuite = {}, count = 1,
+ tests = {}, curTestName,
+ tostring = {}.toString;
+
+ BUNYIP = testsuite;
+
+ /* Yeti uses socket.io and emits a results event when test suite has completed */
+ function complete(results) {
+ console.log(results);
+ $yetify.socket.json.emit("results", results);
+ }
+
+ function type(obj) {
+ return tostring.call(obj).match(/^\[object\s+(.*?)\]$/)[1];
+ }
+
+ function message(result) {
+ if(result.result === "fail") {
+ if(result.actual != undef && result.expected != undef) {
+ if(!result.message) result.message = "";
+ var expectedType = type(result.expected),
+ actualType = type(result.actual);
+
+ result.message = result.message + "\nExpected: " + result.expected.toString() + " (" + expectedType + ")\nActual: " + result.actual.toString() + " (" + actualType + ")";
+
+ // Delete props so we don't get any circular refs
+ delete result.actual;
+ delete result.expected;
+ }
+ }
+
+ return result.message || "";
+ }
+
+ QUnit.log = function(test) {
+ tests["test"+count] = {
+ message: test.message,
+ result: (test.result) ? test.result : "fail",
+ name: "test"+count,
+ actual: test.actual,
+ expected: test.expected
+ };
+
+ count++;
+ };
+
+ QUnit.moduleStart = function(test) {
+ curTestName = test.name;
+ };
+
+ /* YUI test keeps a global of all modules and their results */
+ QUnit.moduleDone = function(test) {
+ var testName = curTestName;
+
+ BUNYIP[testName] = {
+ name: testName,
+ passed: test.passed,
+ failed: test.failed,
+ total: test.total
+ };
+
+ for (var i in tests) {
+ BUNYIP[testName][tests[i].name] = {
+ result: tests[i].result,
+ message: message(tests[i]),
+ name: tests[i].name
+ };
+ }
+
+ tests = {};
+ count = 1;
+ };
+
+ QUnit.done = function(tests) {
+ var results = BUNYIP;
+
+ results.passed = tests.passed;
+ results.failed = tests.failed;
+ results.total = tests.total;
+ results.duration = tests.runtime;
+ results.name = document.title;
+
+ complete(results);
+ };
+
+})(this);

0 comments on commit dbbbe5d

Please sign in to comment.