node.js - Mocha Not Showing All Tests -



i have unit tests in mocha, , when run these 2/3 of tests show up. using speck reporter, , running tests thru make.

here makefile:

reporter = list tests = test/*.js test/**/*.js test/**/**/*.js require = should  test:     @node_env=test node_path=./app/controllers ./node_modules/.bin/mocha \     --reporter $(reporter) \     --ui tdd \     --require $(require) \     -g \     $(tests)  test-ci:     @node_env=ci node_path=./app/controllers ./node_modules/.bin/mocha \     --reporter $(reporter) \     --ui tdd \     --require $(require) \     $(tests)  start:     node_path=./app/controllers node_env=development nodemon server.js  .phony: test 

and test/test.js:

/*!  * module dependencies.  */  var request = require('supertest') var app = require('../server') var mongoose = require('mongoose') var config = require('../config/config')[process.env.node_env]; // other stuff want include tests   function cleardb(done) {   (function(done) {     var index = 0;     var models = mongoose.modelnames();      function deletemodel(err) {       if (err) {         return done(err)       };       if (index == models.length) {         return done()       };       mongoose.model(models[index]).remove({}, deletemodel);       index++;     }     deletemodel();   })(done) }  before(function(done) {   this.timeout(0)   cleardb(done); })  function populatedatabase(functions, done) {   func = mongoose.model("kifunction");   var functions = 0;    if (typeof functions == 'function') {     done = functions     functions = 20   }    function addfunction(err) {     if (err) {       done(err);     }     if (functions < functions) {       functions++;       var func = new func({         string: ("n*" + functions),         approved1: true,         approved2: true,         approved: true,       }).save(addfunction);     } else {       done();     }   }   addfunction(); }  describe('functions', function() {     describe('get /functions/get', function() {       it('should text/kinoki-function', function(done) {         this.timeout(0)         populatedatabase(11, function(err) {           if (err) done(err)           request(app)             .get("/functions/get")             .query('n=[]')             .expect('content-type', new regexp("kinoki-function"))             .expect(200)             .end(function(err, res) {               if (err) return done(err)               else done()             })         })       })       it('should have 10 functions', function(done) {         this.timeout(0)         populatedatabase(25, function(err) {           if (err) return done(err)           request(app)             .get("/functions/get")             .query('n=[]')             .expect(200)             .end(function(err, res) {               var body = res.text               body.split("|").length.should.equal(10)               if (err) return done(err)               done()             })         })         it('each of them should match function pattern', function(done) {           this.timeout(0)           populatedatabase(11, function(err) {             if (err) return done(err)             request(app)               .get("/functions/get")               .query('n=[]')               .expect(200)               .end(function(err, res) {                 var body = res.text                 body.split("|").foreach(function(func) {                   func.should.match(/[0-9]#n([+\-*\/][0-9]+)+#(easy|medium|hard|deadly)+#[0-9a-fa-f]{24}/)                 })                 if (err) return done(err)                 done()               })           })         })         it('should return \'false\' when there no functions', function(done) {           this.timeout(0)           cleardb(function(err) {             if (err) done(err)             request(app)               .get("/functions/get")               .query('n=[]')               .expect(200)               .end(function(err, res) {                 if (err) return done(err)                 res.text.should.equal("false")                 done()               })           })         })         it('should not throw error when no array of functions exclude in querystring', function(done) {           this.timeout(0)           cleardb(function(err) {             if (err) done(err)             request(app)               .get("/functions/get")               .end(function(err, res) {                 if (err) return done(err)                 res.status.should.not.equal(500)                 res.status.should.equal(200)                 done()               })           })         })       })        describe("post /functions/submit", function() {         this.timeout(0)         it("should not 404", function(done) {           request(app)             .post("/functions/submit")             .end(function(err, res) {               if (err) return done(err)               res.status.should.not.equal(404)               done()             })         })         it("should 400 (bad request) without querystring", function(done) {           request(app)             .post("/functions/submit")             .end(function(err, res) {               if (err) return done(err)               res.status.should.equal(400)               done()             })         })       })     }) })       after(function(done) {       // stuff       done()     }) 

and here output mocha:

03:48 pm kinoki-server ari$ make test express app started on port 9273

functions /functions/get ✓ should text/kinoki-function (67ms) ✓ should have 10 functions (76ms) post /functions/submit ✓ should not 404 ✓ should 400 (bad request) without querystring

4 passing (224 ms)

03:52 pm kinoki-server ari$

it says 4 passing, have 6 tests! why mocha hiding other tests?

my guess when directly nest calls it inside each other, mocha doesn't them registered properly. stick pattern of every call it must directly within describe callback , see if fixes it.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -