Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add tests for real

  • Loading branch information...
commit 429c8d45cc4e5b0404ad42ffbdbe74c54f34feea 1 parent 6d5f3e1
@ded authored
Showing with 261 additions and 0 deletions.
  1. +79 −0 vendor/sink.css
  2. +182 −0 vendor/sink.js
View
79 vendor/sink.css
@@ -0,0 +1,79 @@
+body {
+ width: 650px;
+ margin: 20px auto;
+ font: 300 16px 'helvetica neue', helvetica, arial;
+ text-shadow: 0 2px 2px #ccc;
+}
+h1 {
+ font-size: 30px;
+ font-weight: 300;
+}
+ol,li {
+ list-style: none;
+}
+ol {
+ -moz-box-shadow: 0 0 5px #ccc;
+ -moz-border-radius: 5px;
+ -webkit-box-shadow: 0 0 5px #ccc;
+ -webkit-border-radius: 5px;
+ box-shadow: 0 0 5px #ccc;
+ border-radius: 5px;
+ padding: 10px;
+}
+li {
+ margin: 3px 5px;
+ padding: 5px;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ overflow: hidden;
+}
+ol > li {
+ opacity: 0;
+ cursor: pointer;
+}
+li span {
+ color: #aaa;
+ text-align: right;
+ display: inline-block;
+ float: right;
+}
+li.fail span {
+ color: red;
+}
+li.pass span {
+ color: green;
+}
+li.fail {
+ background-color: #eed5d2;
+}
+li.pass {
+ background-color: #bdfcc9;
+}
+li.pass, li.fail {
+ -webkit-transition: opacity .5s linear;
+ opacity: 1;
+}
+li ul {
+ height: 0;
+ overflow: hidden;
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+li.pass ul.show {
+ -webkit-box-shadow: 0 0 5px green;
+}
+li.fail ul.show {
+ -webkit-box-shadow: 0 0 5px red;
+}
+li ul.show {
+ height: auto;
+ padding: 5px;
+ -webkit-border-radius: 5px;
+ margin: 5px;
+}
+li ul li {
+ padding: 0;
+ margin: 2px 0;
+ list-style: none;
+}
View
182 vendor/sink.js
@@ -0,0 +1,182 @@
+/*!
+ * Sink - Browser & Headless JavaScript Unit Tester
+ * copyright Dustin Diaz & Jacob Thornton
+ *
+ */
+!function(context) {
+ var total = 0,
+ fail = false,
+ tests = [],
+ item,
+ setPasses = true,
+ beforeMethods = [],
+ afterMethods = [],
+ currentSetName,
+ isHeadless = (typeof module !== 'undefined' && module.exports);
+
+ isHeadless && require('colors');
+
+ function reset() {
+ total = 0;
+ fail = false;
+ init();
+ }
+
+ function failure(li, check) {
+ setPasses = false;
+ if (!isHeadless) {
+ check.innerHTML = '';
+ li.className = 'fail';
+ }
+ reset();
+ }
+
+ function pass(li, check) {
+ if (!isHeadless) {
+ check.innerHTML = '';
+ li.className = 'pass';
+ }
+ reset();
+ }
+
+ function before(fn) {
+ fn ? beforeMethods.push(fn) : beforeMethods.forEach(function (f) {
+ f();
+ });
+ }
+
+ function after(fn) {
+ fn ? afterMethods.push(fn) : afterMethods.forEach(function (f) {
+ f();
+ });
+ }
+
+ function bind(li) {
+ li.onclick = function() {
+ this.getElementsByTagName('ul')[0].className = 'show';
+ };
+ }
+
+ function _test(name, expect, fn) {
+ before();
+ total = expect;
+ var li, check;
+ if (!isHeadless) {
+ li = document.createElement('li');
+ li.innerHTML = name + ' ... <span>o</span><ul></ul>';
+ item = li.getElementsByTagName('ul')[0];
+ bind(li);
+ check = li.getElementsByTagName('span')[0];
+ document.getElementById('tests').appendChild(li);
+ } else {
+ console.log((name + '...').yellow);
+ }
+
+ var start = +new Date;
+ fn();
+ setTimeout(function() {
+ if (+new Date - start > 10000) {
+ failure(li, check);
+ after();
+ } else {
+ if (fail) {
+ failure(li, check);
+ after();
+ } else if (!total) {
+ after();
+ pass(li, check);
+ } else {
+ setTimeout(arguments.callee, 10);
+ }
+ }
+ }, 10);
+ }
+
+ function test(name, expect, fn) {
+ tests.push({
+ name: name,
+ expect: expect,
+ fn: fn
+ });
+ }
+
+ function init() {
+ if (tests.length) {
+ var o = tests.shift();
+ _test(o.name, o.expect, o.fn);
+ } else {
+ setPasses = true;
+ start();
+ }
+ }
+
+ function ok(b, message) {
+ if (isHeadless) {
+ if (b) {
+ console.log((message + '').green);
+ } else {
+ console.log((message + '').red);
+ }
+ } else {
+ var li = document.createElement('li');
+ li.innerHTML = message + ' ' + (b ? '' : '');
+ item.appendChild(li);
+ }
+
+ if (b) {
+ total--;
+ } else {
+ fail = true;
+ }
+ }
+
+ function expose() {
+ for (var i=0; i < arguments.length; i++) {
+ context[arguments[i].name] = arguments[i];
+ }
+ }
+
+ var modules = [];
+
+ function sink(name, fn) {
+ modules.push({
+ name: name,
+ fn: fn
+ });
+ }
+
+ function nextGroup(name, fn) {
+ beforeMethods = [];
+ afterMethods = [];
+ console.log('MODULE: ' + name);
+ fn(test, ok, before, after);
+ currentSetName = name;
+ init();
+ }
+
+ function start() {
+ var current = modules.shift();
+ current ? nextGroup(current.name, current.fn) : !function () {
+ var message = [
+ 'Congratulations! All tests have passed!',
+ 'There were some errors! The suite has failed.'
+ ];
+ if (isHeadless) {
+ message = message[setPasses ? 0 : 1].toUpperCase();
+ if (setPasses) {
+ console.log(message.rainbow);
+ } else {
+ console.log(message.red);
+ }
+ }
+ }();
+ }
+
+ if (isHeadless) {
+ exports.sink = sink;
+ exports.start = start;
+ } else {
+ expose(sink, start);
+ }
+
+}(this);
Please sign in to comment.
Something went wrong with that request. Please try again.