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 9.0.0 to 9.1.0

2

cjs/lib/compile-route.js

@@ -124,3 +124,3 @@ const { getDebug } = require('./debug');

validateRoute(route);
route.matcher = generateMatcher(route);
route.matcher = generateMatcher(route, this);
limit(route);

@@ -127,0 +127,0 @@ delayResponse(route);

@@ -141,3 +141,3 @@ const { debug, setDebugPhase, getDebug } = require('./debug');

debug(`Attempting to match request to a route`);
if (this.config.fallbackToNetwork === 'always') {
if (this.getOption('fallbackToNetwork') === 'always') {
debug(

@@ -156,3 +156,3 @@ ' Configured with fallbackToNetwork=always - passing through to fetch'

if (this.config.warnOnFallback) {
if (this.getOption('warnOnFallback')) {
console.warn(`Unmatched ${(options && options.method) || 'GET'} to ${url}`); // eslint-disable-line

@@ -168,3 +168,3 @@ }

if (!this.config.fallbackToNetwork) {
if (!this.getOption('fallbackToNetwork')) {
throw new Error(

@@ -171,0 +171,0 @@ `fetch-mock: No fallback response defined for ${(options &&

@@ -5,2 +5,3 @@ const { debug, setDebugNamespace } = require('./debug');

const querystring = require('querystring');
const isSubset = require('is-subset');
const {

@@ -119,3 +120,6 @@ headers: headerUtils,

const getBodyMatcher = ({ body: expectedBody }) => {
const getBodyMatcher = (route, fetchMock) => {
const matchPartialBody = fetchMock.getOption('matchPartialBody', route);
const { body: expectedBody } = route;
debug('Generating body matcher');

@@ -140,4 +144,12 @@ return (url, { body, method = 'get' }) => {

debug('Actual body:', sentBody);
if (matchPartialBody) {
debug('matchPartialBody is true - checking for partial match only');
}
return sentBody && isEqual(sentBody, expectedBody);
return (
sentBody &&
(matchPartialBody
? isSubset(sentBody, expectedBody)
: isEqual(sentBody, expectedBody))
);
};

@@ -208,3 +220,3 @@ };

module.exports = route => {
module.exports = (route, fetchMock) => {
setDebugNamespace('generateMatcher()');

@@ -217,3 +229,3 @@ debug('Compiling matcher for route');

route.params && getParamsMatcher(route),
route.body && getBodyMatcher(route),
route.body && getBodyMatcher(route, fetchMock),
route.functionMatcher && getFunctionMatcher(route),

@@ -220,0 +232,0 @@ route.url && getUrlMatcher(route)

@@ -56,2 +56,6 @@ const { debug } = require('./debug');

FetchMock.getOption = function(name, route = {}) {
return name in route ? route[name] : this.config[name];
};
module.exports = FetchMock;

@@ -97,3 +97,3 @@ const { getDebug } = require('./debug');

getOption(name) {
return name in this.route ? this.route[name] : this.fetchMock.config[name];
return this.fetchMock.getOption(name, this.route);
}

@@ -100,0 +100,0 @@

@@ -23,8 +23,3 @@ const { debug, setDebugPhase } = require('./debug');

const overwriteRoutes =
'overwriteRoutes' in route
? route.overwriteRoutes
: this.config.overwriteRoutes;
if (overwriteRoutes === false || !clashes.length) {
if (this.getOption('overwriteRoutes', route) === false || !clashes.length) {
this._uncompiledRoutes.push(uncompiledRoute);

@@ -34,3 +29,3 @@ return this.routes.push(route);

if (overwriteRoutes === true) {
if (this.getOption('overwriteRoutes', route) === true) {
clashes.forEach(clash => {

@@ -37,0 +32,0 @@ const index = this.routes.indexOf(clash);

@@ -146,3 +146,3 @@ 'use strict';

validateRoute(route);
route.matcher = generateMatcher(route);
route.matcher = generateMatcher(route, this);
limit(route);

@@ -149,0 +149,0 @@ delayResponse(route);

@@ -255,3 +255,3 @@ 'use strict';

debug('Attempting to match request to a route');
if (this.config.fallbackToNetwork === 'always') {
if (this.getOption('fallbackToNetwork') === 'always') {
debug(' Configured with fallbackToNetwork=always - passing through to fetch');

@@ -268,3 +268,3 @@ return { response: this.getNativeFetch(), responseIsFetch: true };

if (this.config.warnOnFallback) {
if (this.getOption('warnOnFallback')) {
console.warn('Unmatched ' + (options && options.method || 'GET') + ' to ' + url); // eslint-disable-line

@@ -280,3 +280,3 @@ }

if (!this.config.fallbackToNetwork) {
if (!this.getOption('fallbackToNetwork')) {
throw new Error('fetch-mock: No fallback response defined for ' + (options && options.method || 'GET') + ' to ' + url);

@@ -283,0 +283,0 @@ }

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

var querystring = require('querystring');
var isSubset = require('is-subset');

@@ -168,10 +169,12 @@ var _require2 = require('./request-utils'),

var getBodyMatcher = function getBodyMatcher(_ref8) {
var expectedBody = _ref8.body;
var getBodyMatcher = function getBodyMatcher(route, fetchMock) {
var matchPartialBody = fetchMock.getOption('matchPartialBody', route);
var expectedBody = route.body;
debug('Generating body matcher');
return function (url, _ref9) {
var body = _ref9.body,
_ref9$method = _ref9.method,
method = _ref9$method === undefined ? 'get' : _ref9$method;
return function (url, _ref8) {
var body = _ref8.body,
_ref8$method = _ref8.method,
method = _ref8$method === undefined ? 'get' : _ref8$method;

@@ -195,4 +198,7 @@ debug('Attempting to match body');

debug('Actual body:', sentBody);
if (matchPartialBody) {
debug('matchPartialBody is true - checking for partial match only');
}
return sentBody && isEqual(sentBody, expectedBody);
return sentBody && (matchPartialBody ? isSubset(sentBody, expectedBody) : isEqual(sentBody, expectedBody));
};

@@ -225,4 +231,4 @@ };

var getFunctionMatcher = function getFunctionMatcher(_ref10) {
var functionMatcher = _ref10.functionMatcher;
var getFunctionMatcher = function getFunctionMatcher(_ref9) {
var functionMatcher = _ref9.functionMatcher;

@@ -276,6 +282,6 @@ debug('Detected user defined function matcher', functionMatcher);

module.exports = function (route) {
module.exports = function (route, fetchMock) {
setDebugNamespace('generateMatcher()');
debug('Compiling matcher for route');
var matchers = [route.query && getQueryStringMatcher(route), route.method && getMethodMatcher(route), route.headers && getHeaderMatcher(route), route.params && getParamsMatcher(route), route.body && getBodyMatcher(route), route.functionMatcher && getFunctionMatcher(route), route.url && getUrlMatcher(route)].filter(function (matcher) {
var matchers = [route.query && getQueryStringMatcher(route), route.method && getMethodMatcher(route), route.headers && getHeaderMatcher(route), route.params && getParamsMatcher(route), route.body && getBodyMatcher(route, fetchMock), route.functionMatcher && getFunctionMatcher(route), route.url && getUrlMatcher(route)].filter(function (matcher) {
return !!matcher;

@@ -282,0 +288,0 @@ });

@@ -71,2 +71,8 @@ 'use strict';

FetchMock.getOption = function (name) {
var route = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return name in route ? route[name] : this.config[name];
};
module.exports = FetchMock;

@@ -119,3 +119,3 @@ 'use strict';

value: function getOption(name) {
return name in this.route ? this.route[name] : this.fetchMock.config[name];
return this.fetchMock.getOption(name, this.route);
}

@@ -122,0 +122,0 @@ }, {

@@ -43,5 +43,3 @@ 'use strict';

var overwriteRoutes = 'overwriteRoutes' in route ? route.overwriteRoutes : this.config.overwriteRoutes;
if (overwriteRoutes === false || !clashes.length) {
if (this.getOption('overwriteRoutes', route) === false || !clashes.length) {
this._uncompiledRoutes.push(uncompiledRoute);

@@ -51,3 +49,3 @@ return this.routes.push(route);

if (overwriteRoutes === true) {
if (this.getOption('overwriteRoutes', route) === true) {
clashes.forEach(function (clash) {

@@ -54,0 +52,0 @@ var index = _this.routes.indexOf(clash);

{
"name": "fetch-mock",
"type": "module",
"version": "9.0.0",
"version": "9.1.0",
"description": "Mock http requests made using fetch (or isomorphic-fetch)",

@@ -60,2 +60,3 @@ "main": "./cjs/server.js",

"glob-to-regexp": "^0.4.0",
"is-subset": "^0.1.1",
"lodash.isequal": "^4.5.0",

@@ -62,0 +63,0 @@ "path-to-regexp": "^2.2.1",

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

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

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

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