Skip to content

Commit

Permalink
fix style, remove global jscs disables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yunong committed Dec 2, 2016
1 parent c72cc34 commit deb275c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 37 deletions.
1 change: 1 addition & 0 deletions .jscsrc
Expand Up @@ -77,6 +77,7 @@
],
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterLineComment": true,
"requireSpaceAfterKeywords": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -61,6 +61,7 @@
"backoff": "^2.4.1",
"bunyan": "^1.8.3",
"dtrace-provider": "^0.7.0",
"fast-safe-stringify": "^1.1.3",
"keep-alive-agent": "0.0.1",
"lodash": "^4.7.0",
"lru-cache": "^4.0.1",
Expand Down
7 changes: 4 additions & 3 deletions test/bunyan.js
@@ -1,6 +1,3 @@
/* eslint-disable no-console, no-undefined */
// jscs:disable maximumLineLength

/*
* Test handling for Bunyan logging in restify-clients.
*/
Expand Down Expand Up @@ -84,7 +81,9 @@ describe('restify-client bunyan usage tests', function () {
setImmediate(callback);
});
} catch (e) {
/* eslint-disable no-console*/
console.error(e.stack);
/* eslint-enable no-console*/
process.exit(1);
}
});
Expand All @@ -94,7 +93,9 @@ describe('restify-client bunyan usage tests', function () {
try {
SERVER.close(callback);
} catch (e) {
/* eslint-disable no-console*/
console.error(e.stack);
/* eslint-enable no-console*/
process.exit(1);
}
});
Expand Down
76 changes: 48 additions & 28 deletions test/index.js
@@ -1,6 +1,5 @@
// Copyright 2012 Mark Cavage <mcavage@gmail.com> All rights reserved.
/* eslint-disable no-console, no-undefined */
// jscs:disable maximumLineLength

'use strict';

Expand Down Expand Up @@ -41,9 +40,11 @@ function sendText(req, res, next) {
if (req.headers.range) {
var matched = req.headers.range.match(/bytes=([0-9]+)-([0-9]*)/);
var start = parseInt(matched[1], 10);
/* eslint-disable no-undefined */
var length = ((matched[2]) ?
parseInt(matched[2], 10) - start :
undefined);
/* eslint-enable no-undefined */
var hash = crypto.createHash('md5');
hash.update(text, 'utf8');
res.header('content-md5', hash.digest('base64'));
Expand Down Expand Up @@ -657,7 +658,8 @@ describe('restify-client tests', function () {
});
});

it('PR-726 Enable {agent: false} option override per request', function (done) {
it('PR-726 Enable {agent: false} option override per request',
function (done) {
var opts = {
path: '/str/noagent',
agent: false
Expand Down Expand Up @@ -688,7 +690,8 @@ describe('restify-client tests', function () {
});

it('requestTimeout', function (done) {
TIMEOUT_CLIENT.get('/str/request_timeout', function (err, req, res, obj) {
TIMEOUT_CLIENT.get('/str/request_timeout',
function (err, req, res, obj) {
assert.ok(err);
assert.equal(err.name, 'RequestTimeoutError');
done();
Expand Down Expand Up @@ -863,6 +866,7 @@ describe('restify-client tests', function () {

it('secure client connection with timeout', function (done) {
var server = restify.createServer({
// jscs:disable maximumLineLength
certificate: '-----BEGIN CERTIFICATE-----\n' +
'MIICgzCCAewCCQDutc3iIPK88jANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMC\n' +
'VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28x\n' +
Expand Down Expand Up @@ -894,6 +898,7 @@ describe('restify-client tests', function () {
'eMp1l9fa7M+ndvKiu2ECQGv4W2+yqlbD3Q3Dr14hiWaiYss5350Ohr5HiZZw2L3i\n' +
's35vQZaHqRxUVZjOi6/MTCZmqvg/RpaVQYHiJHvxGzw=\n' +
'-----END RSA PRIVATE KEY-----'
// jscs:enable maximumLineLength
});

server.get('/ping', function (req, res) {
Expand Down Expand Up @@ -942,9 +947,11 @@ describe('restify-client tests', function () {
}

// Capture the bunyan logs as of
// https://github.com/trentm/node-bunyan/blob/master/test/raw-stream.test.js#L19-L24
CapturingStream.prototype.checkEntriesTest = function checkEntriesTest() {

// jscs:disable maximumLineLength
// github.com/trentm/node-bunyan/blob/master/test/raw-stream.test.js#L19-L24
// jscs:enable maximumLineLength
CapturingStream.prototype.checkEntriesTest =
function checkEntriesTest() {
assert.equal(this.entries.length, 1);
};

Expand Down Expand Up @@ -982,10 +989,8 @@ describe('restify-client tests', function () {

client.get('/json/mcavage', function (err, req, res, obj) {
err;
//assert.ok(req);
//assert.ok(res);

// The verification is done in the CapturingStream.checkEntriesTest()
// The verification is done in the
// CapturingStream.checkEntriesTest()
done();
});
});
Expand Down Expand Up @@ -1058,27 +1063,30 @@ describe('restify-client tests', function () {
var clientWithProxy = clients.createHttpClient('http://10.3.100.207');
assert.ok(clientWithProxy.proxy);

//Blanket wildcard
// Blanket wildcard
process.env.NO_PROXY = '*';
var clientWithoutProxy = clients.createHttpClient('http://192.168.2.1:');
var clientWithoutProxy =
clients.createHttpClient('http://192.168.2.1:');
assert.equal(false, clientWithoutProxy.proxy);

//Multiple addresses
// Multiple addresses
process.env.NO_PROXY = '192.168.2.1, 192.168.2.2';
clientWithoutProxy = clients.createHttpClient('http://192.168.2.1:');
assert.equal(false, clientWithoutProxy.proxy);
clientWithoutProxy = clients.createHttpClient('http://192.168.2.2:');
assert.equal(false, clientWithoutProxy.proxy);

//Port specificity
// Port specificity
process.env.NO_PROXY = '192.168.2.1:8080';
clientWithoutProxy = clients.createHttpClient('http://192.168.2.1:8080');
clientWithoutProxy =
clients.createHttpClient('http://192.168.2.1:8080');
clientWithProxy = clients.createHttpClient('http://192.168.2.1');
assert.ok(clientWithProxy.proxy);
assert.equal(false, clientWithoutProxy.proxy);
done();

//Setting process.env.https_proxy to undefined, converts it to 'undefined'
// Setting process.env.https_proxy to undefined, converts it to
// 'undefined'
if (typeof (origProxy) === 'undefined') {
delete process.env.https_proxy;
} else {
Expand Down Expand Up @@ -1133,7 +1141,8 @@ describe('restify-client tests', function () {
var testTitle = method.toUpperCase() + ' ' + code + ' ';

it(testTitle + ' text', function (done) {
STR_CLIENT[method]('/redirect/' + code + '/str%2Fmcavage', function (err, req, res, data) {
STR_CLIENT[method]('/redirect/' + code + '/str%2Fmcavage',
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1144,7 +1153,8 @@ describe('restify-client tests', function () {
});

it(testTitle + ' json', function (done) {
JSON_CLIENT[method]('/redirect/' + code + '/json%2Fmcavage', function (err, req, res, obj) {
JSON_CLIENT[method]('/redirect/' + code + '/json%2Fmcavage',
function (err, req, res, obj) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1159,7 +1169,8 @@ describe('restify-client tests', function () {

it(testTitle + ' text', function (done) {
var body = 'hello=foo';
STR_CLIENT[method]('/redirect/' + code + '/str%2Fmcavage', body, function (err, req, res, data) {
STR_CLIENT[method]('/redirect/' + code + '/str%2Fmcavage',
body, function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1171,7 +1182,8 @@ describe('restify-client tests', function () {

it(testTitle + ' json', function (done) {
var data = { hello: 'foo' };
JSON_CLIENT[method]('/redirect/' + code + '/json%2Fmcavage', data, function (err, req, res, obj) {
JSON_CLIENT[method]('/redirect/' + code + '/json%2Fmcavage',
data, function (err, req, res, obj) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1183,7 +1195,8 @@ describe('restify-client tests', function () {

// do not assert body on head requests
it('HEAD ' + code + ' text', function (done) {
STR_CLIENT.head('/redirect/' + code + '/str%2Fmcavage', function (err, req, res, data) {
STR_CLIENT.head('/redirect/' + code + '/str%2Fmcavage',
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1193,7 +1206,8 @@ describe('restify-client tests', function () {
});

it('HEAD ' + code + ' json', function (done) {
JSON_CLIENT.head('/redirect/' + code + '/json%2Fmcavage', function (err, req, res, data) {
JSON_CLIENT.head('/redirect/' + code + '/json%2Fmcavage',
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1212,7 +1226,8 @@ describe('restify-client tests', function () {
var testTitle = method.toUpperCase() + ' 307 ';

it(testTitle + ' text', function (done) {
STR_CLIENT[method]('/redirect/307/str%2Fmcavage', function (err, req, res, data) {
STR_CLIENT[method]('/redirect/307/str%2Fmcavage',
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1223,7 +1238,8 @@ describe('restify-client tests', function () {
});

it(testTitle + ' json', function (done) {
JSON_CLIENT[method]('/redirect/307/json%2Fmcavage', function (err, req, res, obj) {
JSON_CLIENT[method]('/redirect/307/json%2Fmcavage',
function (err, req, res, obj) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1238,7 +1254,8 @@ describe('restify-client tests', function () {

it(testTitle + ' text', function (done) {
var body = 'hello=foo';
STR_CLIENT[method]('/redirect/307/str%2Fmcavage', body, function (err, req, res, data) {
STR_CLIENT[method]('/redirect/307/str%2Fmcavage', body,
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1250,7 +1267,8 @@ describe('restify-client tests', function () {

it(testTitle + ' json', function (done) {
var data = { hello: 'foo' };
JSON_CLIENT[method]('/redirect/307/json%2Fmcavage', data, function (err, req, res, obj) {
JSON_CLIENT[method]('/redirect/307/json%2Fmcavage', data,
function (err, req, res, obj) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1262,7 +1280,8 @@ describe('restify-client tests', function () {

// do not assert body on head requests
it('HEAD 307 text', function (done) {
STR_CLIENT.head('/redirect/307/str%2Fmcavage', function (err, req, res, data) {
STR_CLIENT.head('/redirect/307/str%2Fmcavage',
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand All @@ -1272,7 +1291,8 @@ describe('restify-client tests', function () {
});

it('HEAD 307 json', function (done) {
JSON_CLIENT.head('/redirect/307/json%2Fmcavage', function (err, req, res, data) {
JSON_CLIENT.head('/redirect/307/json%2Fmcavage',
function (err, req, res, data) {
assert.ifError(err);
assert.ok(req);
assert.ok(res);
Expand Down
2 changes: 0 additions & 2 deletions test/nock.js
@@ -1,6 +1,4 @@
// Copyright 2012 Mark Cavage <mcavage@gmail.com> All rights reserved.
/* eslint-disable no-console, no-undefined */
// jscs:disable maximumLineLength

'use strict';

Expand Down
10 changes: 6 additions & 4 deletions test/proxy.js
@@ -1,6 +1,3 @@
/* eslint-disable no-console, no-undefined */
// jscs:disable maximumLineLength

/*
* Test handling for restify-clients' HTTP proxy handling.
*/
Expand Down Expand Up @@ -47,9 +44,10 @@ describe('restify-client proxy tests', function () {
before(function (callback) {
try {
// A forward-proxy adapted from
// JSSTYLED
// jscs:disable maximumLineLength
// <https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/reverse-proxy.js>
// (where it is incorrectly named a "reverse" proxy).
// jscs:enable maximumLineLength
PROXYSERVER = http.createServer();

PROXYSERVER.on('connect', function (req, socket) {
Expand All @@ -72,7 +70,9 @@ describe('restify-client proxy tests', function () {
setImmediate(callback);
});
} catch (e) {
/* eslint-disable no-console */
console.error(e.stack);
/* eslint-enable no-console */
process.exit(1);
}
});
Expand All @@ -81,7 +81,9 @@ describe('restify-client proxy tests', function () {
try {
PROXYSERVER.close(callback);
} catch (e) {
/* eslint-disable no-console */
console.error(e.stack);
/* eslint-enable no-console */
process.exit(1);
}
});
Expand Down

0 comments on commit deb275c

Please sign in to comment.