node-sink-test-1.0.2/src/sink.css0000664000175000017500000000326211716255117015624 0ustar metalmetalbody { 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; } ol.sink-pass { background-color: lightgreen; } ol.sink-failure { background-color: lightpink; } li { margin: 3px 5px; padding: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; overflow: hidden; cursor: pointer; } ol > li { opacity: 0; background-color: lightblue; color: #000; } 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, li.mod { -webkit-transition: opacity .5s linear; opacity: 1; } li ul { height: 0; overflow: hidden; margin: 0; padding: 0; list-style: none; position: relative; /*early IE overflow bug*/ } li ul.show { position: static; /*early IE overflow bug*/ } li.pass ul.show { background-color: #8fffa3; } li.fail ul.show { background-color: #efada4; } li ul.show { height: auto; padding: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; margin: 5px; } li ul li { padding: 3px 6px; margin: 2px 0; list-style: none; font-size: 15px; } li b { display: block; margin-left: 40px; } li em.marker { display: block; position: absolute; right: 5px; top: 0; } node-sink-test-1.0.2/src/sink.js0000664000175000017500000002514211716255117015451 0ustar metalmetal/*! * Sink - Browser & Headless JavaScript Unit Tester * copyright Dustin Diaz 2012 * https://github.com/ded/sink-test * License MIT */ !function(context) { var total = 0 , logKey = '' , fail = false , modules = [] , tests = [] , item , setPasses = true , allPass = true , beforeMethods = [] , afterMethods = [] , currentSetName , isHeadless = (typeof module !== 'undefined' && module.exports) isHeadless ? (require('colors')) : String.prototype.__defineGetter__ && !function () { each(['red', 'green', 'magenta', 'rainbow', 'yellow'], function (color) { String.prototype.__defineGetter__(color, function () { return this.replace(/( )/, '$1') // stupid workaround to not log an object }) String.prototype.__defineSetter__(color, function (v) {}) }) }() !isHeadless && window && !('console' in window) && !function () { context.console = {log: function () {}} }() function reset() { total = 0 fail = false init() } function failure(li, check) { setPasses = false allPass = false if (!isHeadless) { check.innerHTML = '✗' li.className = 'fail' } reset() } function each(items, fn) { for (var i = 0; i < items.length; i++) fn(items[i]) } function pass(li, check) { if (!isHeadless) { check.innerHTML = '✓' li.className = 'pass' } reset() } function before(fn) { fn ? beforeMethods.push(fn) : each(beforeMethods, function (f) { f() }) } function after(fn) { fn ? afterMethods.push(fn) : each(afterMethods, function (f) { f() }) } function bind(li) { li.onclick = function() { var ul = this.getElementsByTagName('ul')[0] ul.className = (ul.className) ? '' : 'show' } } function _test(name, expect, fn) { var li, check, start , checker = function () { if (sink.timeout && (+new Date - start > sink.timeout)) { failure(li, check) after() } else { if (fail) { failure(li, check) after() } else if (!total) { after() pass(li, check) } else { setTimeout(arguments.callee, 10) } } } , complete = function () { if (total == -1) ok(false, 'No expectations!') total = 0 } before() if (typeof expect == 'function') { fn = expect total = -1 } else { total = expect } if (!isHeadless) { li = document.createElement('li') li.innerHTML = name + ' ... o' item = li.getElementsByTagName('ul')[0] bind(li) check = li.getElementsByTagName('span')[0] document.getElementById('tests').appendChild(li) } else { console.log(logKey + (name + '...').yellow) } start = +new Date fn.apply(null, total == -1 ? [ complete ] : []) setTimeout(checker, 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 same(actual, expected) { return actual === expected } var toPrintableString = typeof JSON !== 'undefined' && JSON.stringify ? function(o) { if (o instanceof RegExp) return o.toString() return JSON.stringify(o) } : function(o) { return Object.prototype.toString.call(o) } function assert(actual, expected, msg, type, fn) { if (typeof type === 'undefined') type = 'same' var b = (fn || same)(actual, expected) , actualStr = toPrintableString(actual) , expectedStr = toPrintableString(expected) , typeStr = 'assert.' + type if (assert.__negateNext) { // a hack to help with testing assert negatives b = !b typeStr = '!' + typeStr delete assert.__negateNext } if (isHeadless) { var message = b ? '' : '\n\t[' + typeStr + ']\n\tactual: ' + actualStr + (fn && fn.length === 1 ? '' : '\n\texpected: ' + expectedStr) if (b) console.log(logKey + msg + (message + ' ✓').green) else console.log(logKey + msg + (message + ' ✗').red) } else { var li = document.createElement('li') , message = '[' + typeStr + ']actual: ' + actualStr + (fn && fn.length === 1 ? '' : 'expected: ' + expectedStr + '') li.className = b ? 'pass' : 'fail' li.innerHTML = (msg || '') + ' ' + message + ' ' + '' + (b ? '✓' : '✗') + '' item.appendChild(li) } if (b) total-- else fail = true } function ok(b, message) { if (isHeadless) { if (b) console.log(logKey + (message + ' ✓').green) else console.log(logKey + (message + ' ✗').red) } else { var li = document.createElement('li') li.className = b ? 'pass' : 'fail' li.innerHTML = message + ' ' + (b ? '✓' : '✗') item.appendChild(li) } if (b) total-- else fail = true } function sink(name, fn) { modules.push({ name: name , fn: fn }) } function nextGroup(name, fn) { beforeMethods = [] afterMethods = [] var mod = ('MODULE: ' + name) if (isHeadless) { console.log(logKey + mod.magenta) } else { var li = document.createElement('li') li.innerHTML = mod document.getElementById('tests').appendChild(li) li.className = 'mod' } fn(test, ok, before, after, assert) 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.' ] , exit = allPass ? 0 : 1 , color = allPass ? 'rainbow' : 'red' , status = allPass ? 'sink-pass' : 'sink-failure' message = message[exit].toUpperCase() if (isHeadless) { console.log(logKey + message[color]) process.exit(exit) } else { document.getElementById('tests').className = status + ' sink-done' } }() } function setLogKey (key) { var log = console.log logKey = key || '$__sinkTest::' console.log = function (msg) { if (~(''+msg).indexOf(logKey)) { log(msg.replace(logKey, '')) } } } if (isHeadless) { exports.sink = sink exports.start = start exports.sink.timeout = 10000 exports.setLogKey = setLogKey } else { context.sink = sink context.start = start context.sink.timeout = 10000 } //------------------- ASSERTIONS ----------------------// // The following code is heavily inspired by BusterJS assertions by @cjno and @augustl // These assertions are mostly compatible with CommonJS Unit-Testing/1.0. var element = typeof document !== 'undefined' && document.createElement('p') assert.add = function (type, fn) { assert[type] = function(actual, expected, msg) { if (fn.length === 1) { msg = expected expected = undefined } return assert(actual, expected, msg, type, fn) } } function isElement(o) { if (!o || !element || !o.nodeType || o.nodeType !== 1) return false try { o.appendChild(p) o.removeChild(p) } catch (ex) { return false } return true } function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]' } function isDate(o) { return typeof o.getTime == "function" && o.getTime() == o.valueOf() } function keys(o) { var k = [] for (var p in o) { if (Object.prototype.hasOwnProperty.call(o, p)) k.push(p) } return k } // yuk, an approximation of a CommonJS deepEqual method, not recursive-safe function equal(actual, expected) { if (actual === expected) return true if (actual == null || expected == null) return actual == expected if (isElement(actual) || isElement(expected)) return false if (isDate(actual) || isDate(expected)) return isDate(actual) && isDate(expected) && actual.getTime() === expected.getTime(); if (actual instanceof RegExp && expected instanceof RegExp) return actual.toString() !== expected.toString() if ((typeof actual !== 'object' || typeof expected !== 'object') && !isArray(actual) && !isArray(expected)) return actual == expected // coerce if (typeof actual !== typeof expected) return false var actualKeys = keys(actual) , expectedKeys = keys(expected) if (actualKeys.length !== expectedKeys.length) return false var key, i = 0 for (; i < expectedKeys.length; i++) { key = expectedKeys[i] if (!Object.prototype.hasOwnProperty.call(actual, key) || !equal(actual[key], expected[key])) return false } return true } assert.add('ok', function(actual) { return actual }, true) assert.add('same', same) assert.add('strictEqual', same) assert.add('notStrictEqual', function(actual, expected) { return !same(actual, expected) }) assert.add('notSame', function(actual, expected) { return !same(actual, expected) }) assert.add('equal', equal) assert.add('deepEqual', equal) assert.add('notEqual', function(actual, expected) { return !equal(actual, expected) }) assert.add('typeOf', function(actual, expected) { return typeof actual === expected }) assert.add('notTypeOf', function(actual, expected) { return typeof actual !== expected }) assert.add('isDefined', function(actual) { return typeof actual !== 'undefined' }) assert.add('isUndefined', function(actual) { return typeof actual === 'undefined' }) assert.add('isNull', function(actual) { return actual === null }) assert.add('isNotNull', function(actual) { return actual !== null }) assert.add('isObject', function(actual) { return typeof actual === 'object' && !!actual }) assert.add('isFunction', function(actual) { return typeof actual === 'function' }) assert.add('isTrue', function(actual) { return actual === true }) assert.add('isFalse', function(actual) { return actual === false }) assert.add('isString', function(actual) { return typeof actual === 'string' }) assert.add('isBoolean', function(actual) { return typeof actual === 'boolean' }) assert.add('isNumber', function(actual) { return typeof actual === 'number' && !isNaN(actual) }) assert.add('isArray', isArray) assert.add('isElement', isElement) }(this) node-sink-test-1.0.2/src/template.html0000664000175000017500000000120011716255117016635 0ustar metalmetal Sink Tests Template

Sink Tests

    node-sink-test-1.0.2/tests/tests.html0000664000175000017500000000070411716255117016547 0ustar metalmetal Sink Tests Template

    Sink Tests

      node-sink-test-1.0.2/tests/tests.js0000664000175000017500000004566411716255117016235 0ustar metalmetalif (typeof module !== 'undefined' && module.exports) { var sinktest = require('../src/sink') , sink = sinktest.sink , start = sinktest.start } sink('first pass', function (test, ok, before, after) { before(function () { console.log('BEFORE') }) after(function () { console.log('AFTER') }) test('should pass a test thing or two', 2, function () { ok(true, 'first thing') ok(true, 'second thing') }) test('should pass even another set of tests a test', 3, function () { ok(1, 'third thing') ok(1, 'fourth thing') ok(1, 'fifth thing') }) }) sink('secondary set', function (t, k, b, a) { b(function () { console.log('secondary before') }) a(function () { console.log('secondary after') }) t('many talented people cannot count to three', 3, function () { k(1, 'one') k(2, 'two') k(3, 'three') }) }) //logkey is a server feature only if (typeof module !== 'undefined' && module.exports) { sink('log key', function (test, ok, before, after) { test('should set a log key, effectively swallowing all logs not from sink', 1, function () { var log = console.log , count = 0 console.log = function () { count++ } sinktest.setLogKey('@fat::') console.log('1') console.log('2') console.log('3') console.log('@fat::huzzah') console.log('4') console.log('5') console.log = log sinktest.setLogKey('') ok(count == 1, 'only logs prefixe with log key make it to console') }) }) } sink('async complete() callback style', function (test, ok, before, after, assert) { test('should not need count', function (complete) { ok(typeof complete == 'function', 'test function argument is a callback') complete() }) test('should not allow assert/ok-less test (SHOULD FAIL)', function (complete) { complete() }) test('should work async (3 checks)', function (complete) { setTimeout(function () { ok(true, 'ok() at 500ms delay') ok(true, 'nothing to see here') assert(true, true, 'meaningless assert') complete() }, 500) }) }) sink('asserts', function (test, ok, before, after, assert) { test('should be able to assert stuff (SOULD FAIL)', 1, function () { assert(1, 6, 'should have same numbers') }) test('should be able to assert stuff. this shows pass', 1, function () { assert(2, 2, 'should have same numbers') }) var exports = {} assert.throws = function(fn) { assert.__negateNext = true return fn() } // the following is copied straight from the CommonJS Unit-Testing Assertions module: // https://github.com/commonjs/commonjs/blob/master/tests/unit-testing/1.0/program.js // (commit) https://github.com/commonjs/commonjs/commit/8203f29d858d4d2adbd2bb911949fac7459ac264 /*************** START COMMONJS STUFF ********************/ // From Node.js test/mjsunit/test-assert.js // Felix Geisendörfer (felixge), backported from NodeJS // Karl Guertin (greyrest), backported from NodeJS // Kris Kowal (kriskowal), conversion to CommonJS // strangely meta, no? function makeBlock(f) { var args = Array.prototype.slice.call(arguments, 1) return function () { return f.apply(this, args) } } /* @rvagg: not supported exports['test AssertionError instanceof Error'] = function () { assert.ok(new assert.AssertionError({}) instanceof Error); }; */ exports['test ok false'] = function () { assert['throws'](makeBlock(assert.ok, false), assert.AssertionError) } exports['test ok(true)'] = makeBlock(assert.ok, true) exports['test ok("test")'] = makeBlock(assert.ok, "test") exports['test equal true false'] = function () { assert['throws'](makeBlock(assert.equal, true, false), assert.AssertionError, 'equal') } exports['test equal null null'] = makeBlock(assert.equal, null, null) exports['test equal undefined undefined'] = makeBlock(assert.equal, undefined, undefined) exports['test equal null undefined'] = makeBlock(assert.equal, null, undefined) exports['test equal 2 "2"'] = makeBlock(assert.equal, 2, "2") exports['test equal "2" 2'] = makeBlock(assert.equal, "2", 2) exports['test equal true true'] = makeBlock(assert.equal, true, true) exports['test notEqual true false'] = makeBlock(assert.notEqual, true, false) exports['test notEqual true true'] = function () { assert['throws'](makeBlock(assert.notEqual, true, true), assert.AssertionError, 'notEqual') } exports['test strictEqual 2 "2"'] = function () { assert['throws'](makeBlock(assert.strictEqual, 2, "2"), assert.AssertionError, 'strictEqual') } exports['test strictEqual null undefined'] = function () { assert['throws'](makeBlock(assert.strictEqual, null, undefined), assert.AssertionError, 'strictEqual') } exports['test notStrictEqual 2 "2"'] = makeBlock(assert.notStrictEqual, 2, "2") //deepEquals //7.2 exports['test 7.2 deepEqual date'] = makeBlock(assert.deepEqual, new Date(2000, 3, 14), new Date(2000, 3, 14)) exports['test 7.2 deepEqual date negative'] = function () { assert['throws'](makeBlock(assert.deepEqual, new Date(), new Date(2000,3,14)), assert.AssertionError, 'deepEqual date') } //7.3 exports['test 7.3 deepEqual 4 "4"'] = makeBlock(assert.deepEqual, 4, "4") exports['test 7.3 deepEqual "4" 4'] = makeBlock(assert.deepEqual, "4", 4) exports['test 7.3 deepEqual true 1'] = makeBlock(assert.deepEqual, true, 1) exports['test 7.3 deepEqual 4 "5"'] = function () { assert['throws'](makeBlock(assert.deepEqual, 4, "5")) } //7.4 // having the same number of owned properties && the same set of keys exports['test 7.4 deepEqual {a:4} {a:4}'] = makeBlock(assert.deepEqual, {a:4}, {a:4}) exports['test 7.4 deepEqual {a:4,b:"2"} {a:4,b:"2"}'] = makeBlock(assert.deepEqual, {a:4,b:"2"}, {a:4,b:"2"}) exports['test 7.4 deepEqual [4] ["4"]'] = makeBlock(assert.deepEqual, [4], ["4"]) exports['test 7.4 deepEqual {a:4} {a:4,b:true}'] = function () { assert['throws'](makeBlock(assert.deepEqual, {a:4}, {a:4,b:true}), assert.AssertionError) } exports['test deepEqual ["a"], {0:"a"}'] = makeBlock(assert.deepEqual, ["a"], {0:"a"}) // (although not necessarily the same order), exports['test deepEqual {a:4,b:"1"} {b:"1",a:4}'] = makeBlock(assert.deepEqual, {a:4,b:"1"}, {b:"1",a:4}) exports['test deepEqual arrays with non-numeric properties'] = function () { var a1 = [1, 2, 3] , a2 = [1, 2, 3] a1.a = "test"; a1.b = true; a2.b = true; a2.a = "test" // @rvagg Object.keys() not universal: assert['throws'](makeBlock(assert.deepEqual, Object.keys(a1), Object.keys(a2)), assert.AssertionError); makeBlock(assert.deepEqual, a1, a2)() } exports['test deepEqual identical prototype'] = function () { // having an identical prototype property var nbRoot = { toString: function(){return this.first+' '+this.last;} } var nameBuilder = function (first, last) { this.first = first this.last = last return this } nameBuilder.prototype = nbRoot var nameBuilder2 = function (first, last) { this.first = first this.last = last return this } nameBuilder2.prototype = nbRoot var nb1 = new nameBuilder('Ryan', 'Dahl') , nb2 = new nameBuilder2('Ryan', 'Dahl') assert.deepEqual(nb1, nb2) /* @rvagg: IMO this is garbage and conflicts with the '["a"], {0:"a"}' test above nameBuilder2.prototype = Object; nb2 = new nameBuilder2('Ryan','Dahl'); assert['throws'](makeBlock(assert.deepEqual, nb1, nb2), assert.AssertionError); */ }; exports['test deepEqual "a" {}'] = function () { assert['throws'](makeBlock(assert.deepEqual, 'a', {}), assert.AssertionError) } exports['test deepEqual "" ""'] = function () { assert.deepEqual("", "") } exports['test deepEqual "" [""]'] = function () { assert['throws'](makeBlock(assert.deepEqual, '', ['']), assert.AssertionError) } exports['test deepEqual [""] [""]'] = function () { assert.deepEqual([""], [""]) } /* @rvagg: not supported exports['test throw AssertionError'] = function () { //Testing the throwing function thrower(errorConstructor){ throw new errorConstructor('test'); } var aethrow = makeBlock(thrower, assert.AssertionError); var aethrow = makeBlock(thrower, assert.AssertionError); //the basic calls work assert['throws'](makeBlock(thrower, assert.AssertionError), assert.AssertionError, 'message'); assert['throws'](makeBlock(thrower, assert.AssertionError), assert.AssertionError); assert['throws'](makeBlock(thrower, assert.AssertionError)); //if not passing an error, catch all. assert['throws'](makeBlock(thrower, TypeError)); //when passing a type, only catch errors of the appropriate type var threw = false; try { assert['throws'](makeBlock(thrower, TypeError), assert.AssertionError); } catch (e) { threw = true; assert.ok(e instanceof TypeError, 'type'); } assert.ok(threw, 'assert.throws with an explicit error is eating extra errors', assert.AssertionError); threw = false; }; */ /*************** END COMMONJS STUFF ********************/ var t, c for (t in exports) { if (exports.hasOwnProperty(t)) { test('CommonJS Unit Testing/1.0: ' + t.replace(/^test /, ''), 1, exports[t]) } } // additional custom assert types test('assert.typeOf()', 6, function () { assert.typeOf('a string', 'string', 'should be a string') assert.__negateNext = true assert.typeOf('a string', 'object', 'should not be an object') assert.typeOf({one:1}, 'object', 'should be an array') assert.typeOf(100, 'number', 'should be a number') assert.__negateNext = true assert.typeOf(100, 'string', 'should not be a string') assert.typeOf(1.1, 'number', 'should be a number') }) test('assert.notTypeOf()', 6, function () { assert.__negateNext = true assert.notTypeOf('a string', 'string', 'should be a string') assert.notTypeOf('a string', 'object', 'should not be an object') assert.__negateNext = true assert.notTypeOf({one:1}, 'object', 'should be an array') assert.__negateNext = true assert.notTypeOf(100, 'number', 'should be a number') assert.notTypeOf(100, 'string', 'should not be a string') assert.__negateNext = true assert.notTypeOf(1.1, 'number', 'should be a number') }) test('assert.isDefined()', 6, function () { assert.isDefined('', 'should be defined') assert.isDefined(1, 'should be defined') assert.isDefined({}, 'should be defined') assert.isDefined([], 'should be defined') assert.isDefined(null, 'should be defined') assert.__negateNext = true assert.isDefined(undefined, 'should not be defined') }) test('assert.isUndefined()', 6, function () { assert.__negateNext = true assert.isUndefined('', 'should not be undefined') assert.__negateNext = true assert.isUndefined(1, 'should not be undefined') assert.__negateNext = true assert.isUndefined({}, 'should not be undefined') assert.__negateNext = true assert.isUndefined([], 'should not be undefined') assert.__negateNext = true assert.isUndefined(null, 'should not be undefined') assert.isUndefined(undefined, 'should be undefined') }) test('assert.isNull()', 6, function () { assert.__negateNext = true assert.isNull('', 'should not be null') assert.__negateNext = true assert.isNull(1, 'should not be null') assert.__negateNext = true assert.isNull({}, 'should not be null') assert.__negateNext = true assert.isNull([], 'should not be null') assert.isNull(null, 'should be null') assert.__negateNext = true assert.isNull(undefined, 'should not be null') }) test('assert.isNotNull()', 6, function () { assert.isNotNull('', 'should not be null') assert.isNotNull(1, 'should not be null') assert.isNotNull({}, 'should not be null') assert.isNotNull([], 'should not be null') assert.__negateNext = true assert.isNotNull(null, 'should be null') assert.isNotNull(undefined, 'should not be null') }) test('assert.isObject()', 6, function () { assert.isObject({}, 'should be an object') assert.isObject([], 'should be an object') assert.__negateNext = true assert.isObject(1, 'should not be an object') assert.__negateNext = true assert.isObject('a string', 'should not be an object') assert.__negateNext = true assert.isObject(null, 'should not be an object') assert.__negateNext = true assert.isObject(undefined, 'should not be an object') }) test('assert.isFunction()', 8, function () { assert.isFunction(function() {}, 'should be a function') assert.isFunction(assert, 'should be a function') assert.__negateNext = true assert.isFunction({}, 'should not be a function') assert.__negateNext = true assert.isFunction([], 'should not be a function') assert.__negateNext = true assert.isFunction(1, 'should not be a function') assert.__negateNext = true assert.isFunction('a string', 'should not be a function') assert.__negateNext = true assert.isFunction(null, 'should not be a function') assert.__negateNext = true assert.isFunction(undefined, 'should not be a function') }) test('assert.isTrue()', 10, function () { assert.isTrue(true, 'should be true') assert.__negateNext = true assert.isTrue(false, 'should not be true') assert.__negateNext = true assert.isTrue(null, 'should not be true') assert.__negateNext = true assert.isTrue(undefined, 'should not be true') assert.__negateNext = true assert.isTrue('', 'should not be true') assert.__negateNext = true assert.isTrue('a string', 'should not be true') assert.__negateNext = true assert.isTrue(1, 'should not be true') assert.__negateNext = true assert.isTrue(0, 'should not be true') assert.__negateNext = true assert.isTrue({}, 'should not be true') assert.__negateNext = true assert.isTrue([], 'should not be true') }) test('assert.isFalse()', 10, function () { assert.isFalse(false, 'should be false') assert.__negateNext = true assert.isFalse(true, 'should not be false') assert.__negateNext = true assert.isFalse(null, 'should not be false') assert.__negateNext = true assert.isFalse(undefined, 'should not be false') assert.__negateNext = true assert.isFalse('', 'should not be false') assert.__negateNext = true assert.isFalse('a string', 'should not be false') assert.__negateNext = true assert.isFalse(1, 'should not be false') assert.__negateNext = true assert.isFalse(0, 'should not be false') assert.__negateNext = true assert.isFalse({}, 'should not be false') assert.__negateNext = true assert.isFalse([], 'should not be false') }) test('assert.isString()', 10, function () { assert.isString('', 'should be a string') assert.isString('a string', 'should be a string') assert.__negateNext = true assert.isString(false, 'should not be a string') assert.__negateNext = true assert.isString(true, 'should not be a string') assert.__negateNext = true assert.isString(null, 'should not be a string') assert.__negateNext = true assert.isString(undefined, 'should not be a string') assert.__negateNext = true assert.isString(1, 'should not be a string') assert.__negateNext = true assert.isString(0, 'should not be a string') assert.__negateNext = true assert.isString({}, 'should not be a string') assert.__negateNext = true assert.isString([], 'should not be a string') }) test('assert.isBoolean()', 10, function () { assert.isBoolean(false, 'should be a boolean') assert.isBoolean(true, 'should be a boolean') assert.__negateNext = true assert.isBoolean('', 'should be a boolean') assert.__negateNext = true assert.isBoolean('a boolean', 'should not be a string') assert.__negateNext = true assert.isBoolean(null, 'should not be a boolean') assert.__negateNext = true assert.isBoolean(undefined, 'should not be a boolean') assert.__negateNext = true assert.isBoolean(1, 'should not be a boolean') assert.__negateNext = true assert.isBoolean(0, 'should not be a boolean') assert.__negateNext = true assert.isBoolean({}, 'should not be a boolean') assert.__negateNext = true assert.isBoolean([], 'should not be a boolean') }) test('assert.isNumber()', 12, function () { assert.isNumber(1, 'should be a number') assert.isNumber(0, 'should be a number') assert.isNumber(-1.1, 'should be a number') assert.isNumber(10000.1010101, 'should be a number') assert.__negateNext = true assert.isNumber('', 'should be a number') assert.__negateNext = true assert.isNumber('a number', 'should not be a string') assert.__negateNext = true assert.isNumber(false, 'should not be a number') assert.__negateNext = true assert.isNumber(true, 'should not be a number') assert.__negateNext = true assert.isNumber(null, 'should not be a number') assert.__negateNext = true assert.isNumber(undefined, 'should not be a number') assert.__negateNext = true assert.isNumber({}, 'should not be a number') assert.__negateNext = true assert.isNumber([], 'should not be a number') }) test('assert.isArray()', 12, function () { assert.isArray([], 'should be an array') assert.isArray([1,2,3], 'should be an array') assert.isArray(new Array(), 'should be an array') assert.__negateNext = true assert.isArray('', 'should not be an array') assert.__negateNext = true assert.isArray('an array', 'should not be an array') assert.__negateNext = true assert.isArray(false, 'should not be an array') assert.__negateNext = true assert.isArray(true, 'should not be an array') assert.__negateNext = true assert.isArray(null, 'should not be an array') assert.__negateNext = true assert.isArray(undefined, 'should not be an array') assert.__negateNext = true assert.isArray(1, 'should not be an array') assert.__negateNext = true assert.isArray(0, 'should not be an array') assert.__negateNext = true assert.isArray({}, 'should not be an array') }) test('single argument custom assert', 2, function () { assert.add('isHairy', function(actual) { return 'big hairy monster' === actual }) assert.isHairy('big hairy monster', 'should be a big hairy monster') assert.__negateNext = true assert.isHairy('this is not a big hairy monster', 'should not be a big hairy monster') }) test('dual argument custom assert', 2, function () { assert.add('matchesRegex', function(actual, expected) { return expected.test(actual) }) assert.matchesRegex('does this match?', / this /, 'should match the regex') assert.__negateNext = true assert.matchesRegex('does this match?', / NO MATCH FOR YOU /, 'should not match the regex') }) }) sink('timeout tests (takes 20 seconds)', function (test, ok, before, after, assert) { before(function () { sink.timeout = false }) test('should pass a test thing or two', 1, function () { setTimeout(function () { ok(true, 'timeout successfully nulled!') }, 20000) }) }) start() node-sink-test-1.0.2/.gitignore0000664000175000017500000000001411716255117015337 0ustar metalmetalnode_modulesnode-sink-test-1.0.2/README.md0000664000175000017500000001063511716255117014640 0ustar metalmetalSink Test --------- An Asynchronous JavaScript Unit Testing Framework designed to run headless, or in the browser. Sink test is used to test JavaScript that is run asynchronously whereby you can specify the number of expectations and Sink will tell you if they each pass successfully or call an optional `complete()` callback to indicate test completion. How to write a Sink test ------------------------ ``` js test('should have foo', 2, function() { $.ajax('/foo', function(resp) { ok(resp.stat == '200') assert(resp.text, 'success', 'should have success') }) }) // alternatively: test('should have foo', function(complete) { $.ajax('/foo', function(resp) { ok(resp.stat == '200') assert(resp.text, 'success', 'should have success') complete() }) }) ``` Loading a suite of tests ------------------------ The above example illustrates the basic syntax of a single test, however loading your tests is done via the *sink* module which exports the test and ok methods. See the example below: ``` js sink('my module', function(test, ok, before, after, assert) { before(function () { // run this before every test }) after(function () { // run this after every test }) test('should have foo', 2, function () { ok(true, 'this is basically true') ok(1 == 1, 'also true for you math majors') }) }) sink('another module', function (t, o, b, a) { test('a failure', 1, function () { ok(1 == 2, 'should fail') }) }) start() // start all test modules ``` Browser support --------------- Any browser that supports JavaScript as well as Headless via command line with Node. (see below) ``` js // tests.js var sink = require('sink') var start = sink.start sink = sink.sink sink('some module', function (test, ok) { // write tests }) sink('another module', function (test, ok) { // write tests }) start() ``` in your terminal $ node path/to/my/tests.js Advanced assertion support -------------------------- Sink Test follows most of the assert module specified in the [CommonJS Unit-Testing/1.0 assert module](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) and gives you additional convenience assertions plus an API to define your own assertions. Basic assert calls perform a strict equals: ``` js assert(actual, expected, message); // performs: actual === expected ``` The `assert` method is extended, giving you aliases for the above: ``` js assert.same(actual, expected, message); assert.strictEqual(actual, expected, message); // and the inverse: assert.notSame(actual, expected, message); assert.notStrictEqual(actual, expected, message); ``` And also an alias for the simple boolean `ok` method: ``` js assert.ok(value, message) ``` A non-strict deep equals is available via: ``` js assert.equals(actual, expected, message); assert.deepEqual(actual, expected, message); // and the inverse: assert.notEqual(actual, expected, message); ``` And many additional assertions to make your tests clear and obvious: ``` js assert.typeOf(value, type, message); // performs a "typeof value == type" assert.notTypeOf(value, type, message); assert.isDefined(value, message); assert.isUndefined(value, message); assert.isNull(value, message); assert.isNotNull(value, message); assert.isObject(value, message); assert.isFunction(value, message); assert.isString(value, message); assert.isNumber(value, message); assert.isTrue(value, message); assert.isFalse(value, message); assert.isBoolean(value, message); assert.isArray(value, message); assert.isElement(value, message); // is the value a DOM element ``` The *message* parameter on all assertions is optional. ### Custom assertions When you have a complex condition to assert, you can define a custom assertion for it with the `assert.add()` method. Simply provide your assertion name and the handler function. Handler functions can take one or two arguments: ``` js // single-argument form: assert.add('isUpperCaseString', function (value) { return typeof value == 'string' && value.toUpperCase() === value; }); // use it: assert.isUpperCaseString('this will fail', 'should be an upper-case string'); // → fail assert.isUpperCaseString('THIS WILL PASS', 'should be an upper-case string'); // → pass // dual-argument form: assert.add('matchesRegex', function (actual, regex) { return typeof actual == 'string' && regex.test(actual); }); // use it: assert.matchesRegex('this will pass', / [wil]+ /, 'should match my " [wil]+ " regex'); ``` Happy testing! node-sink-test-1.0.2/package.json0000664000175000017500000000072311716255117015644 0ustar metalmetal{ "name": "sink-test" , "description": "Headless / Browser JavaScript Unit Tester" , "version": "1.0.2" , "author": "Dustin Diaz (http://dustindiaz.com)" , "contributors": [ "Rod Vagg (http://github.com/rvagg)" ] , "keywords": ["testing", "unit tests", "headless", "tdd", "async"] , "main": "./src/sink.js" , "engines": { "node": ">= 0.4.0" } , "dependencies": { "colors": ">= 0.5.0" } } node-sink-test-1.0.2/src/0000775000175000017500000000000011716255117014143 5ustar metalmetalnode-sink-test-1.0.2/tests/0000775000175000017500000000000011716255117014516 5ustar metalmetalnode-sink-test-1.0.2/0000775000175000017500000000000011716255117013354 5ustar metalmetal