Skip to content

Commit

Permalink
Add tests, move tests to mocha, add jshint runner
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Apr 23, 2012
1 parent e8a6db5 commit fdbaf26
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
23 changes: 23 additions & 0 deletions .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
}
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -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": ""
}
}
8 changes: 8 additions & 0 deletions 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"
11 changes: 1 addition & 10 deletions 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
53 changes: 53 additions & 0 deletions 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();
});
});
});
14 changes: 0 additions & 14 deletions test/tests.js

This file was deleted.

0 comments on commit fdbaf26

Please sign in to comment.