Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
fix(#84): lint files properly
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Dec 18, 2015
1 parent 82539b7 commit e0cf472
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 47 deletions.
40 changes: 20 additions & 20 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Base (opts) {
Emitter.call(this)
this.replays = []
this.opts = opts || {}
this.mw = new MwPool
this.mw = new MwPool()
}

Base.prototype = Object.create(Emitter.prototype)
Expand All @@ -30,7 +30,7 @@ Base.prototype = Object.create(Emitter.prototype)
* @param {String} url
* @param {Object} opts
* @return {Base}
* @method target
* @method target
* @alias forward
* @alias forwardTo
*/
Expand All @@ -52,7 +52,7 @@ Base.prototype.forwardTo = function (url, opts) {
*
* @param {Array} urls
* @return {Base}
* @method balance
* @method balance
*/

Base.prototype.balance = function (urls) {
Expand All @@ -72,7 +72,7 @@ Base.prototype.balance = function (urls) {
* @param {String} url
* @param {Object} opts
* @return {Base}
* @method replay
* @method replay
* @alias replayTo
*/

Expand All @@ -93,7 +93,7 @@ Base.prototype.replayTo = function (url, opts) {
*
* @param {Object} opts
* @return {Base}
* @method options
* @method options
*/

Base.prototype.options = function (opts) {
Expand All @@ -108,8 +108,8 @@ Base.prototype.options = function (opts) {
*
* @param {Function} filter
* @return {Base}
* @method sequential
* @alias replayAfterForward
* @method sequential
* @alias replayAfterForward
*/

Base.prototype.sequential =
Expand All @@ -125,7 +125,7 @@ Base.prototype.replayAfterForward = function (filter) {
*
* @param {Function} filter
* @return {Base}
* @method replaySequentially
* @method replaySequentially
*/

Base.prototype.replaySequentially = function (filter) {
Expand All @@ -146,7 +146,7 @@ Base.prototype.replaySequentially = function (filter) {
* @param {Object} opts
* @param {Function} filter
* @return {Base}
* @method retry
* @method retry
*/

Base.prototype.retry = function (opts, filter) {
Expand All @@ -159,7 +159,7 @@ Base.prototype.retry = function (opts, filter) {
* Shortcut method to stop replaying HTTP traffic.
*
* @return {Base}
* @method stopReplay
* @method stopReplay
*/

Base.prototype.stopReplay = function () {
Expand All @@ -172,7 +172,7 @@ Base.prototype.stopReplay = function () {
*
* @param {Object} headers
* @return {Base}
* @method headers
* @method headers
*/

Base.prototype.headers = function (headers) {
Expand All @@ -185,7 +185,7 @@ Base.prototype.headers = function (headers) {
*
* @param {Object} query
* @return {Base}
* @method query
* @method query
*/

Base.prototype.query = function (query) {
Expand All @@ -198,7 +198,7 @@ Base.prototype.query = function (query) {
*
* @param {Number} ms
* @return {Base}
* @method timeout
* @method timeout
*/

Base.prototype.timeout = function (ms) {
Expand All @@ -212,8 +212,8 @@ Base.prototype.timeout = function (ms) {
*
* @param {Function} filter
* @return {Base}
* @method bufferBody
* @aliases inteceptBody
* @method bufferBody
* @alias inteceptBody
*/

Base.prototype.bufferBody =
Expand All @@ -229,7 +229,7 @@ Base.prototype.interceptBody = function (filter) {
* @param {String} phase
* @param {Function} middleware
* @return {Base}
* @method useFor
* @method useFor
*/

Base.prototype.useFor = function () {
Expand All @@ -242,7 +242,7 @@ Base.prototype.useFor = function () {
*
* @param {Function} middleware
* @return {Base}
* @method useForward
* @method useForward
*/

Base.prototype.useForward = function () {
Expand All @@ -255,7 +255,7 @@ Base.prototype.useForward = function () {
*
* @param {Function} middleware
* @return {Base}
* @method useReplay
* @method useReplay
*/

Base.prototype.useReplay = function () {
Expand All @@ -268,8 +268,8 @@ Base.prototype.useReplay = function () {
*
* @param {Function} middleware
* @return {Base}
* @method useResponse
* @aliases useOutgoing
* @method useResponse
* @alias useOutgoing
*/

Base.prototype.useOutgoing =
Expand Down
5 changes: 3 additions & 2 deletions lib/rocky.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ module.exports = Rocky
function Rocky (opts) {
if (!(this instanceof Rocky)) return new Rocky(opts)
opts = opts || {}
Base.call(this, opts)

this.server = null
this.router = router(opts.router)
Base.call(this, opts)
this._setupMiddleware()
}

Expand All @@ -39,7 +40,7 @@ Rocky.prototype = Object.create(Base.prototype)
*/

Rocky.prototype.protocol = function (name) {
if (name === 'ws') this.opts.ws = true
if (name === 'ws') this.opts.ws = true
return this
}

Expand Down
1 change: 0 additions & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Base = require('./base')
const middleware = require('./middleware')
const assign = require('lodash').assign

module.exports = Route

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"node": ">= 0.12"
},
"scripts": {
"test": "standard lib/**/*.js test/**/*.js --global suite --global test --global beforeEach --global afterEach && mocha --timeout 10000 --bail --reporter spec --ui tdd test/*.js test/*/*.js test/*/*/*.js",
"test": "standard lib/*.js lib/**/*.js test/*.js test/**/*.js --global suite --global test --global beforeEach --global afterEach && mocha --timeout 10000 --bail --reporter spec --ui tdd test/*.js test/*/*.js test/*/*/*.js",
"bench": "bash benchmark/run.sh"
},
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ suite('helpers', function () {

test('isRegExp', function () {
expect(helpers.isRegexp(/0-9/)).to.be.true
expect(helpers.isRegexp(new RegExp)).to.be.true
expect(helpers.isRegexp(new RegExp())).to.be.true
expect(helpers.isRegexp(null)).to.be.false
expect(helpers.isRegexp([])).to.be.false
expect(helpers.isRegexp({})).to.be.false
Expand All @@ -26,17 +26,17 @@ suite('helpers', function () {
})

test('cloneRequest', function () {
var req = new http.IncomingMessage
var req = new http.IncomingMessage()
req.headers = { foo: 'bar' }
req.rocky = { options: { foo: { bar: true }} }
req.rocky = { options: { foo: { bar: true } } }

var newReq = helpers.cloneRequest(req)
expect(newReq).to.not.be.equal(req)
expect(newReq.rocky).to.not.be.equal(req.rocky)
expect(newReq.headers).to.not.be.equal(req.headers)
expect(newReq.rocky.options).to.not.be.equal(req.rocky.options)
expect(newReq.rocky.options.foo).to.not.be.equal(req.rocky.options.foo)
expect(newReq.__proto__).to.be.equal(req.__proto__)
expect(Object.getPrototypeOf(newReq)).to.be.equal(Object.getPrototypeOf(req))
})

test('permute', function () {
Expand Down
30 changes: 15 additions & 15 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ suite('http', function () {
.end(assert)

function assert (err, res) {
expect(err).to.not.be.empty
expect(res.statusCode).to.be.equal(502)
expect(spy.args.length).to.be.equal(3)
done()
Expand Down Expand Up @@ -243,7 +244,7 @@ suite('http', function () {
expect(req.url).to.be.equal('/test')
expect(res.statusCode).to.be.equal(204)
expect(req.body).to.be.equal(body)
if (replays == 2) done()
if (replays === 2) done()
}
})

Expand Down Expand Up @@ -611,7 +612,7 @@ suite('http', function () {
expect(req.url).to.be.equal('/payload')
expect(req.body).to.be.equal('{"salutation":"hello world"}')
expect(res.statusCode).to.be.equal(204)
if (calls == 2) done()
if (calls === 2) done()
}
})

Expand Down Expand Up @@ -761,6 +762,7 @@ suite('http', function () {

function assert (err, res) {
var errorMsg = /missing target URL/i
expect(err).to.be.null
expect(spy.calledTwice).to.be.true
expect(res.statusCode).to.be.equal(502)
expect(spy.args[0][0].message).to.match(errorMsg)
Expand All @@ -787,6 +789,7 @@ suite('http', function () {
.end(end)

function end (err, res) {
expect(err).to.not.be.empty
expect(spy.calledOnce).to.be.true
expect(res.statusCode).to.be.equal(502)
expect(res.body.message).to.match(/^Route not configured/i)
Expand Down Expand Up @@ -909,12 +912,12 @@ suite('http', function () {
replay = createReplayServer(spy)

proxy.options({ replayAfterForward: true })
proxy.get('/test')
proxy
.get('/test')
.forward('http://invalid')
.replay(replayUrl)
proxy.listen(ports.proxy)

var start = Date.now()
supertest(proxyUrl)
.get('/test')
.expect(502)
Expand Down Expand Up @@ -946,6 +949,7 @@ suite('http', function () {
.end(end)

function end (err, res) {
expect(err).to.be.null
expect(spy.calledTwice).to.be.true
expect(spy.args[1][0].message).to.match(/ENOTFOUND/)
done()
Expand All @@ -966,12 +970,13 @@ suite('http', function () {

supertest(proxyUrl)
.get('/test')
.expect(404)
.expect(502)
.expect('Content-Type', 'application/json')
.expect(/Cannot forward/i)
.end(end)

function end (err, res) {
expect(err).to.be.null
expect(spy.calledTwice).to.be.true
expect(spy.args[0][0].message).to.match(/Target URL/i)
}
Expand Down Expand Up @@ -1179,6 +1184,7 @@ suite('http', function () {
.end(end)

function end (err, res) {
expect(err).to.not.be.null
expect(spy.calledOnce).to.be.true
expect(serverSpy.calledOnce).to.be.true
expect(err.code).to.be.equal('ECONNRESET')
Expand All @@ -1197,9 +1203,9 @@ suite('http', function () {
var spy2 = sinon.spy()
var spy3 = sinon.spy()

var server1 = createServer(9893, 200, spy1)
var server2 = createServer(9894, 201, spy2)
var server3 = createServer(9895, 202, spy3)
createServer(9893, 200, spy1)
createServer(9894, 201, spy2)
createServer(9895, 202, spy3)

proxy = rocky()
proxy
Expand Down Expand Up @@ -1238,7 +1244,7 @@ suite('http', function () {
server = createTestServer(assert)
proxy.get('/test')

var app = connect()
connect()
.use(proxy.middleware())
.listen(ports.proxy)

Expand Down Expand Up @@ -1300,10 +1306,4 @@ function longString (x) {
return crypto.randomBytes(+x || 1024 * 1024)
}

function defer (fn, ms) {
setTimeout(function () {
fn.apply(null, arguments)
}, +ms || 10)
}

function noop () {}
4 changes: 0 additions & 4 deletions test/websocket.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const fs = require('fs')
const WebSocket = require('ws')
const http = require('http')
const sinon = require('sinon')
const supertest = require('supertest')
const expect = require('chai').expect
const rocky = require('..')

Expand Down

0 comments on commit e0cf472

Please sign in to comment.