Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-mocks-http

Package Overview
Dependencies
Maintainers
4
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mocks-http - npm Package Compare versions

Comparing version 1.5.6 to 1.6.1

2

CONTRIBUTING.md

@@ -153,3 +153,3 @@ # Contributing

Then simply run the tests.
Then simply run the tests. This also checks that the code adheres to the ESLint rules.

@@ -156,0 +156,0 @@ npm test

@@ -7,39 +7,47 @@ 'use strict';

var eslint = require('gulp-eslint');
var sequence = require('run-sequence');
var files = {
src: ['./lib/**/*.js'],
test: ['./test/**/*.spec.js']
src: ['./lib/**/*.js'],
test: ['./test/**/*.spec.js', './*.js']
};
gulp.task('lint', function () {
return gulp.src(files.src.concat(files.test))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
return gulp.src(files.src.concat(files.test))
.pipe(eslint({
// configFile: './.eslintrc',
useEslintrc: true
}))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('test', function () {
return gulp.src(files.test, {read: false})
.pipe(mocha({reporter: 'dot'}));
gulp.task('dot', function () {
return gulp.src(files.test, {read: false})
.pipe(mocha({reporter: 'dot'}));
});
gulp.task('test', function (done) {
sequence('dot', 'lint', done);
});
gulp.task('spec', function () {
return gulp.src(files.test, {read: false})
.pipe(mocha({reporter: 'spec'}));
return gulp.src(files.test, {read: false})
.pipe(mocha({reporter: 'spec'}));
});
gulp.task('coverage', function (done) {
gulp.src(files.src)
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src(files.test)
.pipe(mocha({reporter: 'dot'}))
.pipe(istanbul.writeReports({
dir: './coverage',
reporters: ['lcov', 'json', 'html'],
reportOpts: { dir: './coverage' }
}))
.on('end', done);
});
gulp.src(files.src)
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src(files.test)
.pipe(mocha({reporter: 'dot'}))
.pipe(istanbul.writeReports({
dir: './coverage',
reporters: ['lcov', 'json', 'html'],
reportOpts: { dir: './coverage' }
}))
.on('end', done);
});
});

@@ -0,1 +1,14 @@

v 1.6.1
-------
- Fix for Issue #130 for method chaining for `cookie()` and `clearCookie()`
- Fix for Issue #131 for adding `finished` to the response
v 1.6.0
-------
- Dropping support for Node's "0" version, but will continue to support v4.
- Verifying our builds with v6 (latest stable) as well as current work (v7)
- Removing dependency on lodash and other bug fixes
v 1.5.4

@@ -2,0 +15,0 @@ -------

@@ -10,35 +10,35 @@ 'use strict';

app.init = function(){
this.cache = {};
this.settings = {};
this.engines = {};
this.defaultConfiguration();
this.cache = {};
this.settings = {};
this.engines = {};
this.defaultConfiguration();
};
app.defaultConfiguration = function(){
this.enable('x-powered-by');
this.set('etag', 'weak');
var env = process.env.NODE_ENV || 'development';
this.set('env', env);
this.set('query parser', 'extended');
this.set('subdomain offset', 2);
this.set('trust proxy', false);
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
configurable: true,
value: true
});
this.enable('x-powered-by');
this.set('etag', 'weak');
var env = process.env.NODE_ENV || 'development';
this.set('env', env);
this.set('query parser', 'extended');
this.set('subdomain offset', 2);
this.set('trust proxy', false);
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
configurable: true,
value: true
});
this.locals = Object.create(null);
this.mountpath = '/';
this.locals.settings = this.settings;
this.set('jsonp callback name', 'callback');
this.locals = Object.create(null);
this.mountpath = '/';
this.locals.settings = this.settings;
this.set('jsonp callback name', 'callback');
if (env === 'production') {
this.enable('view cache');
}
if (env === 'production') {
this.enable('view cache');
}
Object.defineProperty(this, 'router', {
get: function() {
throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');
}
});
Object.defineProperty(this, 'router', {
get: function() {
throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');
}
});
};

@@ -53,52 +53,52 @@

app.use = function use() {
return this;
return this;
};
app.engine = function() {
return this;
return this;
};
app.param = function() {
return this;
return this;
};
app.set = function(setting, val){
if (arguments.length === 1) {
return this.settings[setting];
}
if (arguments.length === 1) {
return this.settings[setting];
}
this.settings[setting] = val;
return this;
this.settings[setting] = val;
return this;
};
app.path = function(){
return '';
return '';
};
app.enabled = function(setting){
return !!this.set(setting);
return !!this.set(setting);
};
app.disabled = function(setting){
return !this.set(setting);
return !this.set(setting);
};
app.enable = function(setting){
return this.set(setting, true);
return this.set(setting, true);
};
app.disable = function(setting){
return this.set(setting, false);
return this.set(setting, false);
};
methods.forEach(function(method){
app[method] = function(){
return this;
};
app[method] = function(){
return this;
};
});
app.all = function(){
return this;
return this;
};
app.del = deprecate.function(app.delete, 'app.del: Use app.delete instead');

@@ -12,17 +12,17 @@ 'use strict';

function createApplication() {
var app = function() {};
var app = function() {};
mixin(app, EventEmitter.prototype, false);
mixin(app, application, false);
mixin(app, EventEmitter.prototype, false);
mixin(app, application, false);
app.request = {
__proto__: request,
app: app
};
app.response = {
__proto__: response.createResponse(),
app: app
};
app.init();
return app;
app.request = {
__proto__: request,
app: app
};
app.response = {
__proto__: response.createResponse(),
app: app
};
app.init();
return app;
}

@@ -29,0 +29,0 @@

@@ -14,13 +14,13 @@ 'use strict';

var req = exports = module.exports = {
__proto__: http.IncomingMessage.prototype
__proto__: http.IncomingMessage.prototype
};
req.header = function(name) {
switch (name = name.toLowerCase()) {
case 'referer':
case 'referrer':
return this.headers.referrer || this.headers.referer;
default:
return this.headers[name];
}
switch (name = name.toLowerCase()) {
case 'referer':
case 'referrer':
return this.headers.referrer || this.headers.referer;
default:
return this.headers[name];
}
};

@@ -31,9 +31,9 @@

req.accepts = function() {
var accept = accepts(this);
return accept.types.apply(accept, arguments);
var accept = accepts(this);
return accept.types.apply(accept, arguments);
};
req.acceptsEncodings = function(){
var accept = accepts(this);
return accept.encodings.apply(accept, arguments);
var accept = accepts(this);
return accept.encodings.apply(accept, arguments);
};

@@ -44,4 +44,4 @@

req.acceptsCharsets = function(){
var accept = accepts(this);
return accept.charsets.apply(accept, arguments);
var accept = accepts(this);
return accept.charsets.apply(accept, arguments);
};

@@ -52,4 +52,4 @@

req.acceptsLanguages = function(){
var accept = accepts(this);
return accept.languages.apply(accept, arguments);
var accept = accepts(this);
return accept.languages.apply(accept, arguments);
};

@@ -60,108 +60,108 @@

req.range = function(size){
var range = this.get('Range');
if (!range) {
return;
}
return parseRange(size, range);
var range = this.get('Range');
if (!range) {
return undefined;
}
return parseRange(size, range);
};
req.param = function param(name, defaultValue) {
var params = this.params || {};
var body = this.body || {};
var query = this.query || {};
var params = this.params || {};
var body = this.body || {};
var query = this.query || {};
if (params[name] !== null && params.hasOwnProperty(name)) {
return params[name];
}
if (body[name] !== null) {
return body[name];
}
if (query[name] !== null) {
return query[name];
}
if (params[name] !== null && params.hasOwnProperty(name)) {
return params[name];
}
if (body[name] !== null) {
return body[name];
}
if (query[name] !== null) {
return query[name];
}
return defaultValue;
return defaultValue;
};
req.is = function(types) {
if (!Array.isArray(types)) {
types = [].slice.call(arguments);
}
return typeis(this, types);
if (!Array.isArray(types)) {
types = [].slice.call(arguments);
}
return typeis(this, types);
};
defineGetter(req, 'protocol', function protocol() {
var proto = this.options.proto;
proto = this.get('X-Forwarded-Proto') || proto;
return proto.split(/\s*,\s*/)[0];
var proto = this.options.proto;
proto = this.get('X-Forwarded-Proto') || proto;
return proto.split(/\s*,\s*/)[0];
});
defineGetter(req, 'secure', function secure(){
return this.protocol === 'https';
return this.protocol === 'https';
});
defineGetter(req, 'ip', function ip(){
return this.options.ip;
return this.options.ip;
});
defineGetter(req, 'subdomains', function subdomains() {
var hostname = this.hostname;
var hostname = this.hostname;
if (!hostname) {
return [];
}
if (!hostname) {
return [];
}
var offset = this.app.get('subdomain offset');
var domains = !isIP(hostname) ? hostname.split('.').reverse() : [hostname];
var offset = this.app.get('subdomain offset');
var domains = !isIP(hostname) ? hostname.split('.').reverse() : [hostname];
return domains.slice(offset);
return domains.slice(offset);
});
defineGetter(req, 'path', function path() {
return parse(this).pathname;
return parse(this).pathname;
});
defineGetter(req, 'hostname', function hostname() {
var host = this.get('X-Forwarded-Host');
var host = this.get('X-Forwarded-Host');
if (!host) {
host = this.get('Host');
}
if (!host) {
host = this.get('Host');
}
if (!host) {
return;
}
if (!host) {
return undefined;
}
var offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
var index = host.indexOf(':', offset);
var offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
var index = host.indexOf(':', offset);
return ~index ? host.substring(0, index) : host;
return ~index ? host.substring(0, index) : host;
});
defineGetter(req, 'host', function host() {
return this.hostname;
return this.hostname;
});
defineGetter(req, 'fresh', function(){
var method = this.method;
var statusCode = this.res.statusCode;
var method = this.method;
var statusCode = this.res.statusCode;
if (method !== 'GET' && method !== 'HEAD') {
return false;
}
if (method !== 'GET' && method !== 'HEAD') {
return false;
}
if (statusCode >= 200 && statusCode < 300 || statusCode === 304) {
return fresh(this.headers, this.res._headers || {});
}
if (statusCode >= 200 && statusCode < 300 || statusCode === 304) {
return fresh(this.headers, this.res._headers || {});
}
return false;
return false;
});
defineGetter(req, 'stale', function stale() {
return !this.fresh;
return !this.fresh;
});
defineGetter(req, 'xhr', function xhr() {
var val = this.get('X-Requested-With') || '';
return val.toLowerCase() === 'xmlhttprequest';
var val = this.get('X-Requested-With') || '';
return val.toLowerCase() === 'xmlhttprequest';
});
'use strict';
function defineGetter(obj, name, getter) {
Object.defineProperty(obj, name, {
configurable: true,
enumerable: true,
get: getter
});
Object.defineProperty(obj, name, {
configurable: true,
enumerable: true,
get: getter
});
}
module.exports = defineGetter;

@@ -32,3 +32,2 @@ 'use strict';

var http = require('./node/http');
var _assign = require('lodash.assign');

@@ -65,6 +64,7 @@ function createResponse(options) {

mockResponse.cookies = {};
mockResponse.finished = false;
mockResponse.headersSent = false;
mockResponse.statusCode = 200;
mockResponse.statusMessage = 'OK';
mockResponse.cookies = {};
mockResponse.headersSent = false;

@@ -78,2 +78,3 @@ mockResponse.cookie = function(name, value, opt) {

return this;
};

@@ -83,2 +84,3 @@

delete mockResponse.cookies[name];
return this;
};

@@ -134,3 +136,3 @@

if (headers) {
mockResponse._headers = _assign(mockResponse._headers, headers);
Object.assign(mockResponse._headers, headers);
}

@@ -382,3 +384,8 @@

mockResponse.end = function(data, encoding) {
if (_endCalled) {
// Do not emit this event twice.
return;
}
mockResponse.finished = true;
mockResponse.headersSent = true;

@@ -385,0 +392,0 @@

@@ -14,28 +14,28 @@ 'use strict';

function IncomingMessage() {
Stream.Readable.call(this);
Stream.Readable.call(this);
this.httpVersionMajor = null;
this.httpVersionMinor = null;
this.httpVersion = null;
this.complete = false;
this.headers = {};
this.rawHeaders = [];
this.trailers = {};
this.rawTrailers = [];
this.httpVersionMajor = null;
this.httpVersionMinor = null;
this.httpVersion = null;
this.complete = false;
this.headers = {};
this.rawHeaders = [];
this.trailers = {};
this.rawTrailers = [];
this.readable = true;
this.readable = true;
this._pendings = [];
this._pendingIndex = 0;
this.upgrade = null;
this._pendings = [];
this._pendingIndex = 0;
this.upgrade = null;
this.url = '';
this.method = null;
this.url = '';
this.method = null;
this.statusCode = null;
this.statusMessage = null;
this.statusCode = null;
this.statusMessage = null;
this._consuming = false;
this._consuming = false;
this._dumped = false;
this._dumped = false;
}

@@ -51,70 +51,70 @@ util.inherits(IncomingMessage, Stream.Readable);

IncomingMessage.prototype.setTimeout = function(msecs, callback) {
if (callback) {
setTimeout(callback, msecs);
}
if (callback) {
setTimeout(callback, msecs);
}
};
IncomingMessage.prototype._addHeaderLines = function(headers, n) {
if (headers && headers.length) {
var raw, dest;
if (this.complete) {
raw = this.rawTrailers;
dest = this.trailers;
} else {
raw = this.rawHeaders;
dest = this.headers;
}
if (headers && headers.length) {
var raw, dest;
if (this.complete) {
raw = this.rawTrailers;
dest = this.trailers;
} else {
raw = this.rawHeaders;
dest = this.headers;
}
for (var i = 0; i < n; i += 2) {
var k = headers[i];
var v = headers[i + 1];
raw.push(k);
raw.push(v);
this._addHeaderLine(k, v, dest);
for (var i = 0; i < n; i += 2) {
var k = headers[i];
var v = headers[i + 1];
raw.push(k);
raw.push(v);
this._addHeaderLine(k, v, dest);
}
}
}
};
IncomingMessage.prototype._addHeaderLine = function(field, value, dest) {
field = field.toLowerCase();
switch (field) {
// Array headers:
case 'set-cookie':
if (!util.isUndefined(dest[field])) {
dest[field].push(value);
} else {
dest[field] = [value];
}
break;
field = field.toLowerCase();
switch (field) {
// Array headers:
case 'set-cookie':
if (!util.isUndefined(dest[field])) {
dest[field].push(value);
} else {
dest[field] = [value];
}
break;
case 'content-type':
case 'content-length':
case 'user-agent':
case 'referer':
case 'host':
case 'authorization':
case 'proxy-authorization':
case 'if-modified-since':
case 'if-unmodified-since':
case 'from':
case 'location':
case 'max-forwards':
if (util.isUndefined(dest[field])) {
dest[field] = value;
}
break;
case 'content-type':
case 'content-length':
case 'user-agent':
case 'referer':
case 'host':
case 'authorization':
case 'proxy-authorization':
case 'if-modified-since':
case 'if-unmodified-since':
case 'from':
case 'location':
case 'max-forwards':
if (util.isUndefined(dest[field])) {
dest[field] = value;
}
break;
default:
if (!util.isUndefined(dest[field])) {
dest[field] += ', ' + value;
} else {
dest[field] = value;
}
}
default:
if (!util.isUndefined(dest[field])) {
dest[field] += ', ' + value;
} else {
dest[field] = value;
}
}
};
IncomingMessage.prototype._dump = function() {
if (!this._dumped) {
this._dumped = true;
}
if (!this._dumped) {
this._dumped = true;
}
};
'use strict';
exports.STATUS_CODES = {
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing',
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
207: 'Multi-Status',
300: 'Multiple Choices',
301: 'Moved Permanently',
302: 'Moved Temporarily',
303: 'See Other',
304: 'Not Modified',
305: 'Use Proxy',
307: 'Temporary Redirect',
308: 'Permanent Redirect',
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Time-out',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed',
413: 'Request Entity Too Large',
414: 'Request-URI Too Large',
415: 'Unsupported Media Type',
416: 'Requested Range Not Satisfiable',
417: 'Expectation Failed',
418: 'I\'m a teapot',
422: 'Unprocessable Entity',
423: 'Locked',
424: 'Failed Dependency',
425: 'Unordered Collection',
426: 'Upgrade Required',
428: 'Precondition Required',
429: 'Too Many Requests',
431: 'Request Header Fields Too Large',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Time-out',
505: 'HTTP Version Not Supported',
506: 'Variant Also Negotiates',
507: 'Insufficient Storage',
509: 'Bandwidth Limit Exceeded',
510: 'Not Extended',
511: 'Network Authentication Required'
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing',
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
207: 'Multi-Status',
300: 'Multiple Choices',
301: 'Moved Permanently',
302: 'Moved Temporarily',
303: 'See Other',
304: 'Not Modified',
305: 'Use Proxy',
307: 'Temporary Redirect',
308: 'Permanent Redirect',
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Time-out',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed',
413: 'Request Entity Too Large',
414: 'Request-URI Too Large',
415: 'Unsupported Media Type',
416: 'Requested Range Not Satisfiable',
417: 'Expectation Failed',
418: 'I\'m a teapot',
422: 'Unprocessable Entity',
423: 'Locked',
424: 'Failed Dependency',
425: 'Unordered Collection',
426: 'Upgrade Required',
428: 'Precondition Required',
429: 'Too Many Requests',
431: 'Request Header Fields Too Large',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Time-out',
505: 'HTTP Version Not Supported',
506: 'Variant Also Negotiates',
507: 'Insufficient Storage',
509: 'Bandwidth Limit Exceeded',
510: 'Not Extended',
511: 'Network Authentication Required'
};

@@ -5,3 +5,3 @@ {

"description": "Mock 'http' objects for testing Express routing functions",
"version": "1.5.6",
"version": "1.6.1",
"homepage": "https://github.com/howardabrams/node-mocks-http",

@@ -47,3 +47,2 @@ "bugs": {

"fresh": "^0.3.0",
"lodash.assign": "^4.0.6",
"merge-descriptors": "^1.0.1",

@@ -55,20 +54,22 @@ "methods": "^1.1.2",

"range-parser": "^1.2.0",
"type-is": "^1.6.4"
"type-is": "^1.6.14"
},
"devDependencies": {
"chai": "^2.2.0",
"eslint": "^0.22.1",
"gulp": "^3.8.11",
"gulp-eslint": "^0.12.0",
"gulp-istanbul": "^0.9.0",
"gulp-mocha": "^2.0.1",
"istanbul": "^0.3.13",
"mocha": "^2.2.4",
"sinon": "^1.14.1",
"sinon-chai": "^2.7.0"
"chai": "^3.5.0",
"eslint": "^3.13.1",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"run-sequence": "~1.2.2",
"sinon": "^1.17.7",
"sinon-chai": "^2.8.0"
},
"scripts": {
"test": "gulp spec",
"spec": "gulp spec",
"test": "gulp test",
"postversion": "npm publish && git push --follow-tags"
}
}

@@ -213,2 +213,15 @@ 'use strict';

it('should allow chaining', function() {
var cookie = {
value: 'value',
options: {
domain: 'foo.bar.com',
path: '/cookie/path'
}
};
var chainedResponse = response.cookie('name', cookie.value, cookie.options);
expect(chainedResponse).to.deep.equal(response);
});
});

@@ -237,2 +250,8 @@

it('should allow chaining', function() {
response.cookie('name', 'value');
var chainedResponse = response.clearCookie('name');
expect(chainedResponse).to.deep.equal(response);
});
});

@@ -560,3 +579,2 @@

response.write = function(data, encoding) {
console.log('data :', data);
return originalWrite(hackedContent, encoding);

@@ -840,3 +858,21 @@ };

describe('.end()', function() {
var response;
beforeEach(function() {
response = mockResponse.createResponse();
});
// Issue 119
it('only emits end once', function() {
var emits = 0;
response.emit = function (event) {
if (event === 'end') {
emits += 1;
}
};
response.end();
response.end();
expect(emits).to.eql(1);
});
it('should inherit from Node OutogingMessage.end()');

@@ -843,0 +879,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc