New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unexpected-http

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unexpected-http - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

45

lib/unexpectedHttp.js

@@ -14,6 +14,12 @@ /*global window*/

var context = {};
this.errorMode = 'nested';
expect(done, 'to be a function');
this.errorMode = 'default';
this.args.pop();
if (typeof value === 'number') {
var expectedResponseError;
if (Object.prototype.toString.call(value) === '[object Error]' || value instanceof Error) {
expectedResponseError = value;
} else if (typeof value === 'number') {
value = {statusCode: value};

@@ -26,12 +32,16 @@ } else if (typeof value === 'string' || (typeof Buffer !== 'undefined' && Buffer.isBuffer(value))) {

var callbackCalled = false;
function handleError(err) {
if (value instanceof Error) {
try {
expect(err, 'to equal', value);
} catch (e) {
return done(e, context);
if (!callbackCalled) {
callbackCalled = true;
if (expectedResponseError) {
try {
expect(err, 'to equal', expectedResponseError);
} catch (e) {
return done(e, context);
}
done(null, context);
} else {
done(err, context);
}
done(null, context);
} else {
done(err, context);
}

@@ -75,2 +85,9 @@ }

}
if (Array.isArray(httpRequest.body) || (httpRequest.body && typeof httpRequest.body === 'object' && (typeof Buffer === 'undefined' || !Buffer.isBuffer(httpRequest.body)))) {
if (!httpRequest.headers.has('Content-Type')) {
httpRequest.headers.set('Content-Type', 'application/json');
}
httpRequest.body = JSON.stringify(httpRequest.body);
}
var headers = httpRequest.headers.toCanonicalObject();

@@ -115,5 +132,11 @@ Object.keys(headers).forEach(function (headerName) {

} catch (e) {
return done(e, context);
if (!callbackCalled) {
callbackCalled = true;
return done(e, context);
}
}
done(null, context);
if (!callbackCalled) {
callbackCalled = true;
done(null, context);
}
}).on('error', handleError);

@@ -120,0 +143,0 @@ }).on('error', handleError).end(httpRequest.body);

{
"name": "unexpected-http",
"version": "1.6.0",
"version": "1.7.0",
"description": "Unexpected plugin for testing http servers",

@@ -41,3 +41,3 @@ "main": "lib/unexpectedHttp.js",

"underscore": "1.7.0",
"unexpected-messy": "2.9.0"
"unexpected-messy": "2.10.0"
},

@@ -44,0 +44,0 @@ "peerDependencies": {

Sorry, the diff of this file is too big to display

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