Socket
Socket
Sign inDemoInstall

fetch-mock

Package Overview
Dependencies
Maintainers
3
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-mock - npm Package Compare versions

Comparing version 7.3.6 to 7.3.7

60

es5/lib/fetch-handler.js

@@ -18,3 +18,6 @@ 'use strict';

var resolve = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(response, url, options, request) {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(_ref, url, options, request) {
var response = _ref.response,
_ref$responseIsFetch = _ref.responseIsFetch,
responseIsFetch = _ref$responseIsFetch === undefined ? false : _ref$responseIsFetch;
return _regenerator2.default.wrap(function _callee$(_context) {

@@ -24,4 +27,4 @@ while (1) {

case 0:
if (!(typeof response === 'function' || typeof response.then === 'function')) {
_context.next = 10;
if (!true) {
_context.next = 14;
break;

@@ -35,21 +38,30 @@ }

response = response(url, options, request);
_context.next = 8;
// in the case of falling back to the network we need to make sure we're using
// the original Request instance, not our normalised url + options
response = request && responseIsFetch ? response(request) : response(url, options, request);
_context.next = 12;
break;
case 5:
_context.next = 7;
if (!(typeof response.then === 'function')) {
_context.next = 11;
break;
}
_context.next = 8;
return response;
case 7:
case 8:
response = _context.sent;
_context.next = 12;
break;
case 8:
case 11:
return _context.abrupt('return', response);
case 12:
_context.next = 0;
break;
case 10:
return _context.abrupt('return', response);
case 11:
case 14:
case 'end':

@@ -63,3 +75,3 @@ return _context.stop();

return function resolve(_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
return _ref2.apply(this, arguments);
};

@@ -108,3 +120,3 @@ }();

if (this.config.fallbackToNetwork === 'always') {
return { response: this.getNativeFetch() };
return { response: this.getNativeFetch(), responseIsFetch: true };
}

@@ -132,7 +144,7 @@

return { response: this.getNativeFetch() };
return { response: this.getNativeFetch(), responseIsFetch: true };
};
FetchMock.generateResponse = function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(route, url, options, request) {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(route, url, options, request) {
var response;

@@ -144,3 +156,3 @@ return _regenerator2.default.wrap(function _callee2$(_context2) {

_context2.next = 2;
return resolve(route.response, url, options, request);
return resolve(route, url, options, request);

@@ -182,3 +194,3 @@ case 2:

return function (_x5, _x6, _x7, _x8) {
return _ref2.apply(this, arguments);
return _ref3.apply(this, arguments);
};

@@ -211,8 +223,8 @@ }();

FetchMock.push = function (_ref3) {
var url = _ref3.url,
options = _ref3.options,
request = _ref3.request,
isUnmatched = _ref3.isUnmatched,
identifier = _ref3.identifier;
FetchMock.push = function (_ref4) {
var url = _ref4.url,
options = _ref4.options,
request = _ref4.request,
isUnmatched = _ref4.isUnmatched,
identifier = _ref4.identifier;

@@ -219,0 +231,0 @@ var args = [url, options];

2

package.json
{
"name": "fetch-mock",
"version": "7.3.6",
"version": "7.3.7",
"description": "Mock http requests made using fetch (or isomorphic-fetch)",

@@ -5,0 +5,0 @@ "main": "src/server.js",

@@ -5,3 +5,8 @@ const responseBuilder = require('./response-builder');

const resolve = async (response, url, options, request) => {
const resolve = async (
{ response, responseIsFetch = false },
url,
options,
request
) => {
// We want to allow things like

@@ -14,13 +19,16 @@ // - function returning a Promise for a response

// have something that looks like neither Promise nor function
while (
typeof response === 'function' ||
typeof response.then === 'function'
) {
while (true) {
if (typeof response === 'function') {
response = response(url, options, request);
// in the case of falling back to the network we need to make sure we're using
// the original Request instance, not our normalised url + options
response =
request && responseIsFetch
? response(request)
: response(url, options, request);
} else if (typeof response.then === 'function') {
response = await response;
} else {
response = await response;
return response;
}
}
return response;
};

@@ -65,3 +73,3 @@

if (this.config.fallbackToNetwork === 'always') {
return { response: this.getNativeFetch() };
return { response: this.getNativeFetch(), responseIsFetch: true };
}

@@ -93,7 +101,7 @@

return { response: this.getNativeFetch() };
return { response: this.getNativeFetch(), responseIsFetch: true };
};
FetchMock.generateResponse = async function(route, url, options, request) {
const response = await resolve(route.response, url, options, request);
const response = await resolve(route, url, options, request);

@@ -100,0 +108,0 @@ // If the response says to throw an error, throw it

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