Skip to content

Commit

Permalink
add coverage and badges
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Sep 2, 2014
1 parent bb1f68a commit c77a83d
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 27 deletions.
24 changes: 23 additions & 1 deletion .gitignore
@@ -1 +1,23 @@
node_modules
# OS X
.DS_Store*
Icon?
._*

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini

# Linux
.directory
*~


# npm
node_modules
*.log
*.gz


# Coveralls
coverage
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
node_js:
- "0.10"
- "0.11"
language: node_js
script: "npm run-script test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2014

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 0 additions & 6 deletions Makefile

This file was deleted.

20 changes: 15 additions & 5 deletions package.json
Expand Up @@ -3,11 +3,21 @@
"version": "1.0.1",
"description": "assert with status codes",
"devDependencies": {
"mocha": "~1.17.0"
"istanbul": "~0.3.0",
"mocha": "~1.17"
},
"repository": {
"type": "git",
"url": "https://github.com/eivindfjeldstad/http-assert.git"
"repository": "jshttp/http-assert",
"files": [
"LICENSE",
"index.js"
],
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"license": "MIT"
"keywords": [
"assert",
"http"
]
}
23 changes: 22 additions & 1 deletion readme.md
@@ -1,4 +1,12 @@
#http-assert

[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

Assert with status codes. Like ctx.throw() in Koa, but with a guard.

##Example
Expand All @@ -16,4 +24,17 @@ try {
```

##Licence
MIT
MIT

[npm-image]: https://img.shields.io/npm/v/http-assert.svg?style=flat-square
[npm-url]: https://npmjs.org/package/http-assert
[travis-image]: https://img.shields.io/travis/jshttp/http-assert.svg?style=flat-square
[travis-url]: https://travis-ci.org/jshttp/http-assert
[coveralls-image]: https://img.shields.io/coveralls/jshttp/http-assert.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/jshttp/http-assert?branch=master
[david-image]: http://img.shields.io/david/jshttp/http-assert.svg?style=flat-square
[david-url]: https://david-dm.org/jshttp/http-assert
[license-image]: http://img.shields.io/npm/l/http-assert.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/http-assert.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/http-assert
28 changes: 14 additions & 14 deletions test.js → test/test.js
@@ -1,68 +1,68 @@
var assert = require('./');
var assert = require('..');
var ok = require('assert');

describe('assert()', function () {
it('should throw when guard is falsy', function () {
var err;

try {
assert(false, 401, 'fail');
} catch (e) {
err = e;
}

ok(err);
ok(err.status == 401);
ok(err.message == 'fail');
ok(err.expose);
})

it('should not throw when guard is truthy', function () {
assert(true, 401, 'fail');
})

it('should accept options for the error object', function () {
var err;

try {
assert(false, 401, 'fail', { expose: false });
} catch (e) {
err = e;
}

ok(err);
ok(err.status == 401);
ok(err.message == 'fail');
ok(!err.expose);
})

it('should not expose 5xx errors', function () {
var err;

try {
assert(false, 500);
} catch (e) {
err = e;
}

ok(err);
ok(err.status == 500);
ok(err.message == 'Internal Server Error');
ok(!err.expose);
});

it('should default to status code 500', function () {
var err;

try {
assert(false, 'fail');
} catch (e) {
err = e;
}

ok(err);
ok(err.status == 500);
ok(err.message == 'fail');
ok(!err.expose);
});
})
})

0 comments on commit c77a83d

Please sign in to comment.