모카에서는 단위 테스트가 몇 개 있으며,이 테스트를 실행하면 2/3의 테스트 만 표시됩니다. 나는 speck 리포터를 사용하고 있습니다.모카가 모든 테스트를 표시하지 않습니다
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
그리고 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 you want to include for 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 be 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 The 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 are 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 an error when no array of functions to exclude is in the 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 be a 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 be a 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) {
// do some stuff
done()
})
그리고 여기 모카의 출력입니다 :
오후 3시 48분 Kinoki - 서버 아리 $ 만들 test Express 응용 프로그램은 포트 9273에서 시작되었습니다.
개 기능 GET/기능/ 얻을 ✓이어야한다 텍스트/kinoki 기능 (67ms) ✓ 10 개 기능 (76ms)를 가지고해야 POST/기능/404 이어야한다 ✓ 제출 ✓ 400 (잘못된이어야한다 (224 밀리) 통과
4 쿼리 문자열이없는 요청)
오후 3시 52분 그것은 4 통과를 말한다 $
Kinoki - 서버 아리,하지만 난 6 개 검사를! 왜 모카는 다른 테스트를 숨기고 있습니까?
감사합니다. –