From e0cf472758618a96efa1dbc8e61ecf8bffe1c9ff Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Fri, 18 Dec 2015 12:48:33 +0100 Subject: [PATCH] fix(#84): lint files properly --- lib/base.js | 40 ++++++++++++++++++++-------------------- lib/rocky.js | 5 +++-- lib/route.js | 1 - package.json | 2 +- test/helpers.js | 8 ++++---- test/http.js | 30 +++++++++++++++--------------- test/websocket.js | 4 ---- 7 files changed, 43 insertions(+), 47 deletions(-) diff --git a/lib/base.js b/lib/base.js index d7599fd..c70b8eb 100644 --- a/lib/base.js +++ b/lib/base.js @@ -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) @@ -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 */ @@ -52,7 +52,7 @@ Base.prototype.forwardTo = function (url, opts) { * * @param {Array} urls * @return {Base} - * @method balance + * @method balance */ Base.prototype.balance = function (urls) { @@ -72,7 +72,7 @@ Base.prototype.balance = function (urls) { * @param {String} url * @param {Object} opts * @return {Base} - * @method replay + * @method replay * @alias replayTo */ @@ -93,7 +93,7 @@ Base.prototype.replayTo = function (url, opts) { * * @param {Object} opts * @return {Base} - * @method options + * @method options */ Base.prototype.options = function (opts) { @@ -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 = @@ -125,7 +125,7 @@ Base.prototype.replayAfterForward = function (filter) { * * @param {Function} filter * @return {Base} - * @method replaySequentially + * @method replaySequentially */ Base.prototype.replaySequentially = function (filter) { @@ -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) { @@ -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 () { @@ -172,7 +172,7 @@ Base.prototype.stopReplay = function () { * * @param {Object} headers * @return {Base} - * @method headers + * @method headers */ Base.prototype.headers = function (headers) { @@ -185,7 +185,7 @@ Base.prototype.headers = function (headers) { * * @param {Object} query * @return {Base} - * @method query + * @method query */ Base.prototype.query = function (query) { @@ -198,7 +198,7 @@ Base.prototype.query = function (query) { * * @param {Number} ms * @return {Base} - * @method timeout + * @method timeout */ Base.prototype.timeout = function (ms) { @@ -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 = @@ -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 () { @@ -242,7 +242,7 @@ Base.prototype.useFor = function () { * * @param {Function} middleware * @return {Base} - * @method useForward + * @method useForward */ Base.prototype.useForward = function () { @@ -255,7 +255,7 @@ Base.prototype.useForward = function () { * * @param {Function} middleware * @return {Base} - * @method useReplay + * @method useReplay */ Base.prototype.useReplay = function () { @@ -268,8 +268,8 @@ Base.prototype.useReplay = function () { * * @param {Function} middleware * @return {Base} - * @method useResponse - * @aliases useOutgoing + * @method useResponse + * @alias useOutgoing */ Base.prototype.useOutgoing = diff --git a/lib/rocky.js b/lib/rocky.js index b170617..b4ede11 100644 --- a/lib/rocky.js +++ b/lib/rocky.js @@ -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() } @@ -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 } diff --git a/lib/route.js b/lib/route.js index 42617d9..0afb53c 100644 --- a/lib/route.js +++ b/lib/route.js @@ -1,6 +1,5 @@ const Base = require('./base') const middleware = require('./middleware') -const assign = require('lodash').assign module.exports = Route diff --git a/package.json b/package.json index 77bd109..a2fb1d8 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/test/helpers.js b/test/helpers.js index fbd0719..2541284 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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 @@ -26,9 +26,9 @@ 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) @@ -36,7 +36,7 @@ suite('helpers', function () { 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 () { diff --git a/test/http.js b/test/http.js index 51ec180..310a126 100644 --- a/test/http.js +++ b/test/http.js @@ -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() @@ -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() } }) @@ -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() } }) @@ -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) @@ -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) @@ -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) @@ -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() @@ -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) } @@ -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') @@ -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 @@ -1238,7 +1244,7 @@ suite('http', function () { server = createTestServer(assert) proxy.get('/test') - var app = connect() + connect() .use(proxy.middleware()) .listen(ports.proxy) @@ -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 () {} diff --git a/test/websocket.js b/test/websocket.js index cfa88f5..d20798f 100644 --- a/test/websocket.js +++ b/test/websocket.js @@ -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('..')