From fdbaf26f25417ec191f9a192fa86af5803b5f983 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 23 Apr 2012 12:06:22 +0200 Subject: [PATCH] Add tests, move tests to mocha, add jshint runner --- .jshintrc | 23 ++++++++++++++++++++++ package.json | 7 ++++++- runhint.sh | 8 ++++++++ runtests.sh | 11 +---------- test/lib.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/tests.js | 14 -------------- 6 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 .jshintrc create mode 100644 runhint.sh create mode 100644 test/lib.js delete mode 100644 test/tests.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..21df4f5 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,23 @@ +{ +"bitwise": true, +"curly": true, +"eqeqeq": true, +"forin": true, +"immed": true, +"latedef": true, +"newcap": true, +"noarg": true, +"noempty": true, +"nonew": true, +"regexp": true, +"undef": true, +"strict": true, +"trailing": true, + +"globalstrict": true, + +"white": true, + +"indent": 4, +"maxlen": 80 +} diff --git a/package.json b/package.json index 6531ed9..fccf8ef 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,12 @@ , "version": "0.0.1" , "private": true , "dependencies": { - "express": "2.4.3" + "express": "" , "jade": ">= 0.0.1" + , "underscore": "", + "async": "", + "mocha": "", + "should": "", + "jshint": "" } } diff --git a/runhint.sh b/runhint.sh new file mode 100644 index 0000000..56bc78f --- /dev/null +++ b/runhint.sh @@ -0,0 +1,8 @@ +FIND_JS="find -name '*.js' ! -path './node_modules/*'" +STATIC="-path './static/*'" +TESTS="-path './test/*'" +JSHINT="xargs -0 -I FILE node_modules/.bin/jshint FILE --show-non-errors" + +sh -c "$FIND_JS ! $STATIC ! $TESTS -print0 | $JSHINT --node +$FIND_JS $TESTS -print0 | $JSHINT --node # --predef describe it +$FIND_JS $STATIC -print0 | $JSHINT --browser" diff --git a/runtests.sh b/runtests.sh index 5e0010b..6584e76 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,10 +1 @@ -PATH=$PATH:~/bin expresso -I . test/* -# Expresso somehow disables strict mode, so we use the following as well -NODE_PATH=. node -e 'var tsts = require("./test/tests"), -assert=require("assert"); -for (var i in tsts) { - if (tsts.hasOwnProperty(i)) { - tsts[i](function () {}, assert); - } -} -' +node_modules/.bin/mocha -R spec diff --git a/test/lib.js b/test/lib.js new file mode 100644 index 0000000..8364da4 --- /dev/null +++ b/test/lib.js @@ -0,0 +1,53 @@ +"use strict"; + +var should = require('should'); +var lib = require('../lib'); + +describe('numSort', function () { + it('should sort numbers by numeric value, ascending', function () { + should.deepEqual(lib.numSort([1, -4.5, 2, 3, -5, 0, 5, 20, 0.2, 9]), + [-5, -4.5, 0, 0.2, 1, 2, 3, 5, 9, 20]); + }); + + it('should gracefully handle an empty argument', function () { + should.deepEqual(lib.numSort([]), []); + }); +}); + +describe('untilValue', function () { + it('should return a found value which is the first', function (done) { + lib.untilValue([ + 1, 5 + ], function (val, ncbValHandled) { + ncbValHandled(val === 5, val === 1 ? (val * 2) : undefined); + }, function (errs, res) { + should.not.exist(errs); + res.should.eql(2); + done(); + }); + }); + + it('should return a found value which is not the first', function (done) { + lib.untilValue([ + 1, 5 + ], function (val, ncbValHandled) { + ncbValHandled(val === 1, val === 5 ? (val * 2) : undefined); + }, function (errs, res) { + should.not.exist(errs); + res.should.eql(10); + done(); + }); + }); + + it('should return errors if no value found', function (done) { + lib.untilValue([ + 1, 5 + ], function (val, ncbValHandled) { + ncbValHandled(val * 2); + }, function (errs, res) { + should.exist(errs); + errs.should.eql([2, 10]); + done(); + }); + }); +}); diff --git a/test/tests.js b/test/tests.js deleted file mode 100644 index 060d48b..0000000 --- a/test/tests.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; - -var lib = require("lib"); - -exports.numSort = function (beforeExit, assert) { - assert.deepEqual(lib.numSort([1, -4.5, 2, 3, -5, 0, 5, 20, 0.2, 9]), - [-5, -4.5, 0, 0.2, 1, 2, 3, 5, 9, 20]); -}; - -/* -exports. = function (beforeExit, assert) { - assert.equal(, ); -}; -*/