Navigation Menu

Skip to content

Commit

Permalink
Use mocha for tests and add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
danmactough committed Apr 5, 2013
1 parent 5252d5c commit 55c68ab
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
6 changes: 6 additions & 0 deletions Makefile
@@ -0,0 +1,6 @@
MOCHA = ./node_modules/mocha/bin/mocha

test:
@$(MOCHA)

.PHONY: test
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Distributed locking mechanism using haredis",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "make test"
},
"repository": {
"type": "git",
Expand All @@ -24,5 +24,8 @@
"dependencies": {
"haredis": "~0.2.10",
"moment": "~1.7.0"
},
"devDependencies": {
"mocha": "~1.9.0"
}
}
20 changes: 20 additions & 0 deletions test/basic.js
@@ -0,0 +1,20 @@
describe('halocksmith', function () {
var cleanup;

after(function (done) {
cleanup(done);
});

it('can create an exclusive lock', function (done) {
var lock = halocksmith({ retries: 0, timeout: 2 });
lock(function (err, release) {
assert.ifError(err);
cleanup = release;
setTimeout(done, 100);
});
lock(function (err, release) {
assert.ok(err instanceof Error);
assert.equal(release, null);
});
});
});
4 changes: 4 additions & 0 deletions test/common.js
@@ -0,0 +1,4 @@
/*global assert: true, halocksmith: true*/

halocksmith = require('../');
assert = require('assert');
24 changes: 0 additions & 24 deletions test/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,4 @@
--require test/common.js
--globals halocksmith,assert
--reporter spec
--timeout 5s

0 comments on commit 55c68ab

Please sign in to comment.