Permalink
Browse files

Switch test helper to mocha

  • Loading branch information...
1 parent 197fbf7 commit 638ae673a40fd708a3632354b693b15afcd0670c @zzdhidden committed Dec 9, 2011
Showing with 98 additions and 131 deletions.
  1. +2 −3 Makefile
  2. +1 −1 package.json
  3. +23 −50 test/collection.test.js
  4. +52 −59 test/db.test.js
  5. +8 −9 test/deferred.test.js
  6. +7 −5 test/mongoq.test.js
  7. +5 −4 test/util.test.js
View
@@ -2,9 +2,8 @@
test:
@echo "Please start mongodb[localhost:27017] at first."
@echo "Test mongoq"
- @NODE_ENV=test ./node_modules/.bin/expresso \
- -I lib \
- test/*.test.js
+ @NODE_ENV=test ./node_modules/.bin/mocha --slow 20 --growl \
+ ./test/*.test.js
docs: docs/api.html
View
@@ -13,7 +13,7 @@
, "jquery-deferred": ">=0.1.0"
}
, "devDependencies": {
- "expresso" : ">=0.9.2"
+ "mocha" : "*"
, "should": ">=0.2.1"
}
, "main": "index"
View
@@ -3,9 +3,8 @@ var mongoq = require('../index.js')
, should = require('should');
var colnum = 1;
-
-module.exports = {
- "test collection options": function(beforeExit) {
+describe("collection", function() {
+ it("test collection options", function(done) {
var users = mongoq("mongoqTest", {auto_reconnect: true}).collection("users", {slaveOk: false})
, hadOpen = false;
users.drop(function() {
@@ -15,15 +14,11 @@ module.exports = {
users.hint = {name: true};
should.exist( originalCol.hint );
originalCol.hint.name.should.be.true;
- hadOpen = true;
- users.db.close();
+ users.db.close(done);
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
- }
- , "test inherit methods": function(beforeExit) {
+ });
+ it( "test inherit methods", function(done) {
var users = mongoq("mongoqTest").collection("users" + (colnum++))
, hadOpen = false;
users.drop(function() {
@@ -35,15 +30,12 @@ module.exports = {
user.phone.should.be.equal(1234567);
user._id.should.be.ok;
hadOpen = true;
- users.db.close();
+ users.db.close(done);
});
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
- }
- , "test find": function(beforeExit) {
+ });
+ it( "test find", function(done) {
var db = mongoq("mongoqTest")
, colname = "users" + (colnum++)
, users = db.collection(colname)
@@ -67,7 +59,7 @@ module.exports = {
user._id.should.be.ok;
users.find(function(err, cursor){
hadOpen2 = true;
- db.close();
+ db.close(done);
});
});
});
@@ -78,14 +70,8 @@ module.exports = {
db.on("open", function() {
num ++;
});
-
- beforeExit(function() {
- hadOpen.should.be.true;
- hadOpen2.should.be.true;
- num.should.be.equal(2);
- });
- }
- , "test findItems": function(beforeExit) {
+ });
+ it( "test findItems", function(done) {
var users = mongoq("mongoqTest").collection("users" + (colnum++))
, hadOpen = false;
users.drop(function() {
@@ -99,15 +85,12 @@ module.exports = {
user.name.should.be.eql("Jack");
user.phone.should.be.equal(1234567);
user._id.should.be.ok;
- users.db.close();
+ users.db.close(done);
});
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
- }
- , "test cursor": function(beforeExit) {
+ });
+ it( "test cursor", function(done) {
var users = mongoq("mongoqTest").collection("users" + (colnum++))
, hadOpen = false;
users.drop(function() {
@@ -121,15 +104,12 @@ module.exports = {
user.name.should.be.eql("Lucy");
user.phone.should.be.equal(123);
user._id.should.be.ok;
- users.db.close();
+ users.db.close(done);
});
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
- }
- , "test group": function(beforeExit) {
+ });
+ it( "test group", function(done) {
var users = mongoq("mongoqTest").collection("users" + (colnum++))
, hadOpen = false;
users.drop(function() {
@@ -147,17 +127,14 @@ module.exports = {
docs[0].count.should.be.equal(1);
docs[0].sex.should.be.equal("male");
hadOpen = true;
- users.db.close();
+ users.db.close(done);
});
});
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
+ });
- }
- , "test insert push": function(beforeExit) {
+ it( "test insert push", function(done) {
var users = mongoq("mongoqTest").collection("users" + (colnum++))
, hadOpen = false;
users.drop(function() {
@@ -167,15 +144,11 @@ module.exports = {
should.exist( user );
user.childrens.should.have.length( 2 );
user.childrens[1].should.equal("Lili");
- users.db.close();
- hadOpen = true;
+ users.db.close( done );
});
});
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
- }
-};
+ });
+});
View
@@ -1,9 +1,10 @@
var mongoq = require('../index.js')
-, should = require('should');
+ , should = require('should');
-module.exports = {
- "test db arguments": function(){
+describe("db", function() {
+
+ it( "test db arguments", function(){
var db = mongoq("mongodb:\/\/fred:foobar@localhost:27017,localhost:27018/mongoqTest?reconnectWait=2000;retries=20");
var options = db.options;
options.should.be.a('object');
@@ -12,10 +13,10 @@ module.exports = {
db.name.should.eql("mongoqTest");
var server = db.server
- , servers = server.servers;
+ , servers = server.servers;
servers.should.have.length( 2 );
var server1 = servers[ 0 ]
- , server2 = servers[ 1 ];
+ , server2 = servers[ 1 ];
server.reconnectWait.should.equal(2000);
server.retries.should.equal(20);
server1.host.should.eql("localhost");
@@ -60,61 +61,59 @@ module.exports = {
server = db.server;
server.host.should.equal("127.0.0.1");
server.port.should.eql(1233);
- }
+ });
- , "test db events[error,close,timeout]": function(beforeExit) {
+ it( "test db events[error,close,timeout]", function( done ) {
var db = mongoq("mongoqTest")
- , db2 = mongoq("mongodb:\/\/127.0.0.1:27019/mongoqTest")
- , dbopen = false
- , db2open = false
- , close = false
- , error = false;
- db.on("close", function() {
- close = true;
- })
- .open(function(err, originalDb) {
- dbopen = true;
- should.exist(originalDb);
- should.equal(err, null);
- db.close();
- });
+ , db2 = mongoq("mongodb:\/\/127.0.0.1:27019/mongoqTest")
+ , dbopen = false
+ , db2open = false
+ , close = false
+ , error = false;
+
db2.on("error", function() {
error = true;
}).on("close", function() {
error = true;
})
- .open(function(err) {
- db2open = true;
- err.should.be.an.instanceof(Error);
- });
- beforeExit(function() {
- should.strictEqual(dbopen, true);
- should.strictEqual(db2open, true);
- should.strictEqual(close, true);
- should.strictEqual(error, true);
- });
- }
- , "test db close": function(beforeExit) {
+ .open(function(err) {
+ db2open = true;
+ err.should.be.an.instanceof(Error);
+
+ db.on("close", function() {
+ close = true;
+ })
+ .open(function(err, originalDb) {
+ dbopen = true;
+ should.exist(originalDb);
+ should.equal(err, null);
+
+ should.strictEqual(dbopen, true);
+ should.strictEqual(db2open, true);
+ should.strictEqual(error, true);
+
+ db.close( done );
+ });
+ });
+
+ } );
+
+ it( "test db close", function(done) {
var db = mongoq("mongoqTest")
- , hadOpen = false
- , hadClose = false;
+ , hadOpen = false
+ , hadClose = false;
db.open(function(err, originalDb) {
hadOpen = true;
should.exist(originalDb);
should.equal(err, null);
})
- .close(function() {
- hadClose = true;
- });
- beforeExit(function() {
- should.strictEqual(hadOpen, true);
- should.strictEqual(hadClose, true);
- });
- }
- , "test db inherit methods": function(beforeExit) {
+ .close(done);
+ } );
+
+ it( "test db inherit methods", function(done) {
var db = mongoq("mongoqTest")
- , hadOpen = false;
+ , hadOpen = false;
db.dropCollection("test", function(err, success) {
db.createCollection("test", function(err, collection) {
should.equal(err, null);
@@ -128,18 +127,15 @@ module.exports = {
if( col.name == "mongoqTest.test" ) hasCollectionTest = true;
});
hasCollectionTest.should.be.true;
- db.close();
+ db.close(done);
});
});
});
- beforeExit(function() {
- should.strictEqual(hadOpen, true);
- });
- }
- , "test db authenticate": function(beforeExit) {
+ } );
+ it( "test db authenticate", function(done) {
var db = mongoq("mongoqTest")
- , db2 = mongoq("mongodb:\/\/admin:foobar@localhost:27017/mongoqTest")
- , hadOpen = false;
+ , db2 = mongoq("mongodb:\/\/admin:foobar@localhost:27017/mongoqTest")
+ , hadOpen = false;
db.removeUser("admin", function(err, success) {
db.addUser("admin", "foobar", function(err, user) {
db.authenticate("admin", "foobar", function(err, success) {
@@ -152,13 +148,10 @@ module.exports = {
hadOpen = true;
db2.isAuthenticate.should.be.true;
should.not.exist(err);
- db2.close();
+ db2.close( done );
});
});
});
});
- beforeExit(function() {
- should.strictEqual(hadOpen, true);
- });
- }
-};
+ });
+});
View
@@ -1,8 +1,8 @@
var mongoq = require('../index.js')
, should = require('should');
-module.exports = {
- "test find": function( beforeExit ){
+describe("deferred", function() {
+ it("should return a promise object when find", function( done ){
var users = mongoq("mongoqTest", {auto_reconnect: true}).collection("users23424")
, hadOpen = false;
@@ -16,16 +16,15 @@ module.exports = {
_users.should.have.length( 2 );
//Deferred not supports find().each()
users.find().each().done(function(user) {
- users.db.close();
+
+ hadOpen.should.be.true;
+ users.db.close(done);
+
});
});
});
});
- beforeExit(function() {
- hadOpen.should.be.true;
- });
-
- }
-};
+ });
+});
View
@@ -1,9 +1,11 @@
var mongoq = require('../index.js')
-, should = require('should');
+ , should = require('should');
-module.exports = {
- 'test .version': function(){
+describe("mongoq", function() {
+
+ it( 'test .version', function(){
mongoq.version.should.match(/^\d+\.\d+\.\d+$/);
- }
-};
+ });
+
+});
Oops, something went wrong.

0 comments on commit 638ae67

Please sign in to comment.