Merge pull request #344 from seegno/enhancement/add-full-coverage
Add full coverage
This commit is contained in:
commit
a462876b25
4 changed files with 89 additions and 4 deletions
|
@ -39,11 +39,12 @@
|
|||
"only": "0.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "^3.1.0",
|
||||
"mocha": "^1.17.0",
|
||||
"supertest": "~0.13.0",
|
||||
"istanbul-harmony": "~0.3.0",
|
||||
"make-lint": "^1.0.1"
|
||||
"make-lint": "^1.0.1",
|
||||
"mocha": "^1.17.0",
|
||||
"should": "^3.1.0",
|
||||
"supertest": "~0.13.0",
|
||||
"test-console": "^0.7.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.11.13"
|
||||
|
|
|
@ -4,6 +4,8 @@ var assert = require('assert');
|
|||
var http = require('http');
|
||||
var koa = require('..');
|
||||
var fs = require('fs');
|
||||
var stderr = require("test-console").stderr;
|
||||
var AssertionError = assert.AssertionError;
|
||||
|
||||
describe('app', function(){
|
||||
it('should handle socket errors', function(done){
|
||||
|
@ -114,6 +116,67 @@ describe('app.use(fn)', function(){
|
|||
})
|
||||
})
|
||||
|
||||
describe('app.onerror(err)', function(){
|
||||
it('should throw an error if a non-error is given', function(done){
|
||||
var app = koa();
|
||||
|
||||
try {
|
||||
app.onerror('foo');
|
||||
|
||||
should.fail();
|
||||
} catch (err) {
|
||||
err.should.be.instanceOf(AssertionError);
|
||||
err.message.should.equal('non-error thrown: foo');
|
||||
}
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
it('should do nothing if status is 404', function(done){
|
||||
var app = koa();
|
||||
var err = new Error();
|
||||
|
||||
err.status = 404;
|
||||
|
||||
var output = stderr.inspectSync(function() {
|
||||
app.onerror(err);
|
||||
});
|
||||
|
||||
output.should.eql([]);
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
it('should do nothing if env is test', function(done){
|
||||
var app = koa();
|
||||
var err = new Error();
|
||||
|
||||
var output = stderr.inspectSync(function() {
|
||||
app.onerror(err);
|
||||
});
|
||||
|
||||
output.should.eql([]);
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
it('should log the error to stderr', function(done){
|
||||
var app = koa();
|
||||
app.env = 'dev';
|
||||
|
||||
var err = new Error();
|
||||
err.stack = 'Foo';
|
||||
|
||||
var output = stderr.inspectSync(function() {
|
||||
app.onerror(err);
|
||||
});
|
||||
|
||||
output.should.eql(["\n", " Foo\n", "\n"]);
|
||||
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
describe('app.respond', function(){
|
||||
describe('when this.respond === false', function(){
|
||||
it('should bypass app.respond', function(done){
|
||||
|
|
11
test/context/inspect.js
Normal file
11
test/context/inspect.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
var context = require('../context');
|
||||
|
||||
describe('ctx.inspect()', function(){
|
||||
it('should return a json representation', function(){
|
||||
var ctx = context();
|
||||
var toJSON = ctx.toJSON(ctx);
|
||||
|
||||
toJSON.should.eql(ctx.inspect());
|
||||
})
|
||||
})
|
10
test/response/socket.js
Normal file
10
test/response/socket.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
var Stream = require('stream');
|
||||
var response = require('../context').response;
|
||||
|
||||
describe('res.socket', function(){
|
||||
it('should return the request socket object', function(){
|
||||
var res = response();
|
||||
res.socket.should.be.instanceOf(Stream);
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue