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

unexpected-http

Package Overview
Dependencies
Maintainers
4
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 5.6.0 to 5.7.0

94

lib/unexpectedHttp.js

@@ -21,7 +21,3 @@ /*global window, setTimeout, clearTimeout, Uint8Array*/

expectedResponseError = value;
} else if (typeof value === 'number') {
value = {statusCode: value};
} else if (typeof value === 'string' || (typeof Buffer !== 'undefined' && Buffer.isBuffer(value))) {
value = {body: value};
} else {
} else if (value && typeof value === 'object' && (typeof Buffer === 'undefined' || !Buffer.isBuffer(value))) {
value = _.extend({}, value);

@@ -34,31 +30,2 @@ if (value.error) {

return expect.promise(function (resolve, reject) {
var callbackCalled = false;
function handleError(err) {
if (!callbackCalled) {
callbackCalled = true;
if (expectedResponseError) {
try {
expect(err, 'to equal', expectedResponseError);
} catch (e) {
return reject(e);
}
resolve(context);
} else if (err.code) {
// Socket or DNS error
try {
expect.fail({
diff: function (output) {
output.error(err.message);
return { diff: output };
},
code: err.code
});
} catch (e) {
reject(e);
}
} else {
reject(err);
}
}
}
var requestOptions = {};

@@ -80,3 +47,3 @@ var requestTimeout = subject.timeout || 0;

if (!subject.isMessyHttpRequest) {
subject = new messy.HttpRequest(subject);
subject = new messy.HttpRequest(subject && typeof subject === 'object' ? _.omit(subject, 'timeout') : subject);
}

@@ -129,4 +96,4 @@

expect.fail('expected a response within {0} ms', requestTimeout);
} catch (e) {
return handleError(e);
} catch (err) {
reject(err);
}

@@ -137,5 +104,2 @@ }, requestTimeout);

var request = (httpRequest.encrypted ? https : http).request(requestOptions).on('response', function (response) {
if (callbackCalled) {
return;
}
var chunks = [];

@@ -145,5 +109,2 @@ response.on('data', function (chunk) {

}).on('end', function () {
if (callbackCalled) {
return;
}
if (timeout) {

@@ -186,21 +147,8 @@ clearTimeout(timeout);

});
expect.promise(function () {
expect(expectedResponseError, 'to be undefined');
return expect(context.httpExchange = new messy.HttpExchange({
request: httpRequest,
response: httpResponse
}), 'to satisfy', {response: value});
}).caught(function (e) {
if (!callbackCalled) {
callbackCalled = true;
return reject(e);
}
}).then(function () {
if (!callbackCalled) {
callbackCalled = true;
resolve(context);
}
});
}).on('error', handleError);
}).on('error', handleError);
resolve(context.httpExchange = new messy.HttpExchange({
request: httpRequest,
response: httpResponse
}));
}).on('error', reject);
}).on('error', reject);

@@ -214,6 +162,26 @@ if (request.xhr) {

requestBody.pipe(request);
requestBody.on('error', handleError);
requestBody.on('error', reject);
} else {
request.end(httpRequest.unchunkedBody);
}
}).then(function (httpExchange) {
expect(expectedResponseError, 'to be undefined');
return expect(httpExchange, 'to satisfy', { response: value });
}, function (err) {
if (expectedResponseError) {
expect(err, 'to equal', expectedResponseError);
} else if (err.code) {
// Socket or DNS error
expect.fail({
diff: function (output) {
output.error(err.message);
return { diff: output };
},
code: err.code
});
} else {
throw err;
}
}).then(function () {
return context;
});

@@ -220,0 +188,0 @@ });

{
"name": "unexpected-http",
"version": "5.6.0",
"version": "5.7.0",
"description": "Unexpected plugin for testing http servers",

@@ -43,6 +43,6 @@ "main": "lib/unexpectedHttp.js",

"dependencies": {
"messy": "^6.16.0",
"passerror": "1.1.0",
"underscore": "1.7.0",
"unexpected-messy": "^6.0.0",
"messy": "^6.6.1"
"unexpected-messy": "^6.5.0"
},

@@ -52,3 +52,3 @@ "peerDependencies": {

"unexpected-messy": "^6.0.0",
"messy": "^6.6.1"
"messy": "^6.16.0"
},

@@ -59,4 +59,4 @@ "devDependencies": {

"coveralls": "2.11.2",
"eslint": "2.7.0",
"eslint-config-onelint": "1.0.2",
"eslint": "2.13.1",
"eslint-config-onelint": "1.2.0",
"hesse": "0.0.1",

@@ -70,3 +70,3 @@ "istanbul": "0.3.4",

"stream-http": "2.4.0",
"unexpected": "10.10.8",
"unexpected": "10.26.3",
"unexpected-documentation-site-generator": "^4.0.0",

@@ -73,0 +73,0 @@ "unexpected-markdown": "^1.4.0"

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