Skip to content

Commit

Permalink
fix(dev): upgrading modules including restify-errors (#1755)
Browse files Browse the repository at this point in the history
* fix: upgraded deps and dev deps  and fixed the needed files and tests
  • Loading branch information
rajatkumar committed Mar 7, 2019
1 parent a67b25f commit 3b71229
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -60,7 +60,7 @@ CLEAN_FILES += $(TAP) ./node_modules/nodeunit
.PHONY: test
test: $(NODEUNIT)
$(NODEUNIT) test/*.test.js
$(MOCHA) test/plugins/*.test.js
$(MOCHA) --full-trace --no-exit test/plugins/*.test.js

.PHONY: docs-build
docs-build:
Expand Down
3 changes: 2 additions & 1 deletion lib/bunyan_helper.js
Expand Up @@ -87,7 +87,8 @@ function RequestCaptureStream(opts) {
this.limit = opts.maxRecords || 100;
this.maxRequestIds = opts.maxRequestIds || 1000;
// eslint-disable-next-line new-cap
this.requestMap = LRU({
// need to initialize using `new`
this.requestMap = new LRU({
max: self.maxRequestIds
});
this.dumpDefault = opts.dumpDefault;
Expand Down
7 changes: 5 additions & 2 deletions lib/errorTypes.js
Expand Up @@ -2,5 +2,8 @@

var errors = require('restify-errors');

errors.makeConstructor('RequestCloseError');
errors.makeConstructor('RouteMissingError');
// This allows Restify to work with restify-errors v6+
module.exports = {
RequestCloseError: errors.makeConstructor('RequestCloseError'),
RouteMissingError: errors.makeConstructor('RouteMissingError')
};
1 change: 0 additions & 1 deletion lib/index.js
Expand Up @@ -11,7 +11,6 @@ var Server = require('./server');
var shallowCopy = require('./utils').shallowCopy;

var InternalError = errors.InternalError;
require('./errorTypes');

/**
* A restify server object is the main interface through which you will register
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/accept.js
Expand Up @@ -38,7 +38,7 @@ function acceptParser(accepts) {
return a;
})
.map(function map(a) {
return a.indexOf('/') === -1 ? mime.lookup(a) : a;
return a.indexOf('/') === -1 ? mime.getType(a) : a;
})
.filter(function filter(a) {
return a;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/static.js
Expand Up @@ -115,7 +115,7 @@ function serveStatic(options) {
fstream.once('open', function onceOpen(fd) {
res.cache({ maxAge: maxAge });
res.set('Content-Length', stats.size);
res.set('Content-Type', mime.lookup(file));
res.set('Content-Type', mime.getType(file));
res.set('Last-Modified', stats.mtime);

if (opts.charSet) {
Expand Down
4 changes: 2 additions & 2 deletions lib/request.js
Expand Up @@ -117,7 +117,7 @@ function patch(Request) {
assert.string(t, 'type');

if (t.indexOf('/') === -1) {
t = mime.lookup(t);
t = mime.getType(t);
}
return t;
});
Expand Down Expand Up @@ -568,7 +568,7 @@ function patch(Request) {
}

if (type.indexOf('/') === -1) {
type = mime.lookup(type);
type = mime.getType(type);
}

if (type.indexOf('*') !== -1) {
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Expand Up @@ -463,7 +463,7 @@ function patch(Response) {
type = type.split(';')[0];

if (!self.formatters[type] && type.indexOf('/') === -1) {
type = mime.lookup(type);
type = mime.getType(type);
}

// If finding a formatter matching the negotiated content-type is
Expand Down
7 changes: 4 additions & 3 deletions lib/server.js
Expand Up @@ -21,6 +21,7 @@ var formatters = require('./formatters');
var shallowCopy = require('./utils').shallowCopy;
var upgrade = require('./upgrade');
var deprecationWarnings = require('./deprecationWarnings');
var customErrorTypes = require('./errorTypes');

// Ensure these are loaded
var patchRequest = require('./request');
Expand Down Expand Up @@ -1095,7 +1096,7 @@ Server.prototype._onHandlerError = function _onHandlerError(
// Cannot find route by name, called when next('route-name') doesn't
// find any route, it's a 5xx error as it's a programatic error
if (!routeHandler) {
var routeByNameErr = new errors.RouteMissingError(
var routeByNameErr = new customErrorTypes.RouteMissingError(
"Route by name doesn't exist"
);
routeByNameErr.code = 'ENOEXIST';
Expand Down Expand Up @@ -1164,7 +1165,7 @@ Server.prototype._setupRequest = function _setupRequest(req, res) {
// we consider a closed request as flushed from metrics point of view
function onReqAborted() {
// Request was aborted, override the status code
var err = new errors.RequestCloseError();
var err = new customErrorTypes.RequestCloseError();
err.statusCode = 444;

// For backward compatibility we only set connection state to "close"
Expand Down Expand Up @@ -1463,7 +1464,7 @@ function mergeFormatters(fmt) {
}

if (k.indexOf('/') === -1) {
k = mime.lookup(k);
k = mime.getType(k);
}

obj[t] = src[k];
Expand Down
21 changes: 10 additions & 11 deletions package.json
Expand Up @@ -95,25 +95,25 @@
"dependencies": {
"assert-plus": "^1.0.0",
"bunyan": "^1.8.12",
"csv": "^1.1.1",
"csv": "^5.1.1",
"escape-regexp-component": "^1.0.2",
"ewma": "^2.0.1",
"find-my-way": "^2.0.1",
"formidable": "^1.2.1",
"http-signature": "^1.2.0",
"lodash": "^4.17.11",
"lru-cache": "^4.1.3",
"mime": "^1.5.0",
"lru-cache": "^5.1.1",
"mime": "^2.4.0",
"negotiator": "^0.6.1",
"once": "^1.4.0",
"pidusage": "^1.2.0",
"pidusage": "^2.0.17",
"qs": "^6.5.2",
"restify-errors": "^5.0.0",
"restify-errors": "^7.0.0",
"semver": "^5.4.1",
"send": "^0.16.2",
"spdy": "^3.4.7",
"spdy": "^4.0.0",
"uuid": "^3.1.0",
"vasync": "^1.6.4",
"vasync": "^2.2.0",
"verror": "^1.10.0"
},
"optionalDependencies": {
Expand All @@ -124,24 +124,23 @@
"autocannon-compare": "^0.3.0",
"chai": "^4.1.2",
"cover": "^0.2.9",
"coveralls": "^2.13.3",
"coveralls": "^3.0.3",
"documentation": "^5.3.3",
"eslint": "4.19.1",
"eslint-config-prettier": "2.9.0",
"eslint-plugin-jsdoc": "3.15.1",
"eslint-plugin-prettier": "2.7.0",
"filed": "^0.1.0",
"glob": "^7.1.2",
"inquirer": "^3.3.0",
"istanbul": "^0.4.5",
"mkdirp": "^0.5.1",
"mocha": "^3.5.3",
"mocha": "^6.0.2",
"nodeunit": "^0.11.2",
"ora": "^1.3.0",
"pre-commit": "^1.2.2",
"prettier": "1.16.1",
"proxyquire": "^1.8.0",
"restify-clients": "^1.5.2",
"restify-clients": "^2.6.4",
"rimraf": "^2.6.2",
"validator": "^7.2.0",
"watershed": "^0.4.0"
Expand Down
2 changes: 2 additions & 0 deletions test/plugins/cpuUsageThrottle.test.js
Expand Up @@ -122,6 +122,8 @@ describe('cpuUsageThrottle', function() {
'Default shed status code returned'
);
clearTimeout(plugin._timeout);
// we should close the server else mocha wont exit
server.close();
done();
});
});
Expand Down
33 changes: 4 additions & 29 deletions test/server.test.js
Expand Up @@ -10,7 +10,6 @@ var http = require('http');
var stream = require('stream');

var errors = require('restify-errors');
var filed = require('filed');
var restifyClients = require('restify-clients');
var uuid = require('uuid');

Expand Down Expand Up @@ -524,32 +523,6 @@ test('get (path and version ok)', function(t) {
});
});

test('GH-56 streaming with filed (download)', function(t) {
SERVER.get('/', function tester(req, res, next) {
filed(__filename).pipe(res);
});

var opts = {
hostname: '127.0.0.1',
port: PORT,
path: '/',
method: 'GET',
agent: false
};
http.request(opts, function(res) {
t.equal(res.statusCode, 200);
var body = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
t.ok(body.length > 0);
t.end();
});
}).end();
});

test('GH-63 res.send 204 is sending a body', function(t) {
SERVER.del('/hello/:name', function tester(req, res, next) {
res.send(204);
Expand Down Expand Up @@ -1215,7 +1188,8 @@ test('res.charSet', function(t) {
SERVER.get('/foo', function getFoo(req, res, next) {
res.charSet('ISO-8859-1');
res.set('Content-Type', 'text/plain');
res.send(200, { foo: 'bar' });
// send a string instead of JSON
res.send(200, JSON.stringify({ foo: 'bar' }));
next();
});

Expand All @@ -1231,7 +1205,8 @@ test('res.charSet override', function(t) {
SERVER.get('/foo', function getFoo(req, res, next) {
res.charSet('ISO-8859-1');
res.set('Content-Type', 'text/plain;charset=utf-8');
res.send(200, { foo: 'bar' });
// send a string instead of JSON
res.send(200, JSON.stringify({ foo: 'bar' }));
next();
});

Expand Down

0 comments on commit 3b71229

Please sign in to comment.