Skip to content

Commit

Permalink
lint: use standard style
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Nov 16, 2016
1 parent 490e638 commit a35d3e9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
node_modules
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "standard"
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ cache:
before_install:
# Setup Node.js version-specific dependencies
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard"
# Update Node.js modules
- "test ! -d node_modules || npm prune"
- "test ! -d node_modules || npm rebuild"
script:
# Run test script, depending on istanbul install
- "test ! -z $(npm -ps ls istanbul) || npm test"
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
after_script:
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = responseTime
* @api public
*/

function responseTime(options) {
function responseTime (options) {
var opts = options || {}

if (typeof options === 'number') {
Expand All @@ -48,10 +48,10 @@ function responseTime(options) {
? createSetHeader(opts)
: opts

return function responseTime(req, res, next) {
return function responseTime (req, res, next) {
var startAt = process.hrtime()

onHeaders(res, function onHeaders() {
onHeaders(res, function onHeaders () {
var diff = process.hrtime(startAt)
var time = diff[0] * 1e3 + diff[1] * 1e-6

Expand All @@ -67,7 +67,7 @@ function responseTime(options) {
* @api private
*/

function createSetHeader(options) {
function createSetHeader (options) {
// response time digits
var digits = options.digits !== undefined
? options.digits
Expand All @@ -81,7 +81,7 @@ function createSetHeader(options) {
? Boolean(options.suffix)
: true

return function setResponseHeader(req, res, time) {
return function setResponseHeader (req, res, time) {
if (res.getHeader(header)) {
return
}
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
},
"devDependencies": {
"after": "0.8.2",
"eslint": "3.10.1",
"eslint-config-standard": "6.2.1",
"eslint-plugin-promise": "3.3.2",
"eslint-plugin-standard": "2.0.1",
"istanbul": "0.4.5",
"mocha": "2.5.3",
"supertest": "1.1.0"
Expand All @@ -33,6 +37,7 @@
"node": ">= 0.8.0"
},
"scripts": {
"lint": "eslint .",
"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/"
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
24 changes: 12 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

process.env.NO_DEPRECATION = 'response-time'

var after = require('after');
var assert = require('assert');
var http = require('http');
var request = require('supertest');
var after = require('after')
var assert = require('assert')
var http = require('http')
var request = require('supertest')
var responseTime = require('..')

describe('responseTime()', function () {
it('should send X-Response-Time header', function (done) {
var server = createServer()
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9\.]+ms$/, done)
.expect('X-Response-Time', /^[0-9.]+ms$/, done)
})

it('should not override X-Response-Time header', function (done) {
var server = createServer(undefined, function(req, res) {
var server = createServer(undefined, function (req, res) {
res.setHeader('X-Response-Time', 'bogus')
})

Expand Down Expand Up @@ -110,14 +110,14 @@ describe('responseTime(options)', function () {
var server = createServer()
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9\.]+ms$/, done)
.expect('X-Response-Time', /^[0-9.]+ms$/, done)
})

it('should allow custom header name', function (done) {
var server = createServer({ header: 'X-Time-Taken' })
request(server)
.get('/')
.expect('X-Time-Taken', /^[0-9\.]+ms$/, done)
.expect('X-Time-Taken', /^[0-9.]+ms$/, done)
})
})

Expand All @@ -126,19 +126,19 @@ describe('responseTime(options)', function () {
var server = createServer()
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9\.]+ms$/, done)
.expect('X-Response-Time', /^[0-9.]+ms$/, done)
})

it('should allow disabling suffix', function (done) {
var server = createServer({ suffix: false })
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9\.]+$/, done)
.expect('X-Response-Time', /^[0-9.]+$/, done)
})
})
})

function createServer(opts, fn) {
function createServer (opts, fn) {
var _responseTime = responseTime(opts)
return http.createServer(function (req, res) {
_responseTime(req, res, function (err) {
Expand All @@ -151,7 +151,7 @@ function createServer(opts, fn) {
})
}

function shouldNotHaveHeader(header) {
function shouldNotHaveHeader (header) {
return function (res) {
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header)
}
Expand Down

0 comments on commit a35d3e9

Please sign in to comment.