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

fetch-mock

Package Overview
Dependencies
Maintainers
0
Versions
236
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 12.4.0 to 12.5.1

dist/cjs/IsSubsetOf.d.ts

15

CHANGELOG.md
# Changelog
## [12.5.1](https://github.com/wheresrhys/fetch-mock/compare/fetch-mock-v12.5.0...fetch-mock-v12.5.1) (2025-03-01)
### Bug Fixes
* improve handling of abort ([5c1085d](https://github.com/wheresrhys/fetch-mock/commit/5c1085d59d0dee600691ba7fba642869a623aa68))
* remove deprecated is-subset-of ([a2546ef](https://github.com/wheresrhys/fetch-mock/commit/a2546ef871e279ca5ef76d925f0491386c0809b2))
## [12.5.0](https://github.com/wheresrhys/fetch-mock/compare/fetch-mock-v12.4.0...fetch-mock-v12.5.0) (2025-03-01)
### Features
* match formdata bodies ([ab7dff4](https://github.com/wheresrhys/fetch-mock/commit/ab7dff427454b6238e2228280a828c19b1f1df31))
## [12.4.0](https://github.com/wheresrhys/fetch-mock/compare/fetch-mock-v12.3.0...fetch-mock-v12.4.0) (2025-02-23)

@@ -4,0 +19,0 @@

29

dist/cjs/Matchers.js

@@ -42,3 +42,3 @@ "use strict";

const regexparam = __importStar(require("regexparam"));
const is_subset_of_1 = require("is-subset-of");
const IsSubsetOf_js_1 = require("./IsSubsetOf.js");
const dequal_1 = require("dequal");

@@ -156,7 +156,21 @@ const RequestUtils_js_1 = require("./RequestUtils.js");

};
const formDataToObject = (formData) => {
const fields = [...formData];
const result = {};
fields.forEach(([key, value]) => {
result[key] = result[key] || [];
result[key].push(value);
});
return result;
};
const getBodyMatcher = (route) => {
const { body: expectedBody } = route;
let { body: expectedBody } = route;
let expectedBodyType = 'json';
if (!expectedBody) {
return;
}
if (expectedBody instanceof FormData) {
expectedBodyType = 'formData';
expectedBody = formDataToObject(expectedBody);
}
return ({ options: { body, method = 'get' } }) => {

@@ -170,8 +184,17 @@ if (['get', 'head', 'delete'].includes(method.toLowerCase())) {

sentBody = JSON.parse(body);
if (expectedBodyType !== 'json') {
return false;
}
}
}
catch { }
if (body instanceof FormData) {
if (expectedBodyType !== 'formData') {
return false;
}
sentBody = formDataToObject(body);
}
return (sentBody &&
(route.matchPartialBody
? (0, is_subset_of_1.isSubsetOf)(expectedBody, sentBody)
? (0, IsSubsetOf_js_1.isSubsetOf)(expectedBody, sentBody)
: (0, dequal_1.dequal)(expectedBody, sentBody)));

@@ -178,0 +201,0 @@ };

@@ -76,3 +76,8 @@ "use strict";

try {
derivedOptions.body = await request.clone().text();
try {
derivedOptions.body = await request.clone().formData();
}
catch {
derivedOptions.body = await request.clone().text();
}
}

@@ -79,0 +84,0 @@ catch { }

@@ -92,6 +92,16 @@ "use strict";

if (requestBody instanceof ReadableStream) {
requestBody.cancel(error);
if (requestBody.locked) {
requestBody.getReader().cancel(error);
}
else {
requestBody.cancel(error);
}
}
if (callLog?.response?.body) {
callLog.response.body.cancel(error);
if (callLog.response.body.locked) {
callLog.response.body.getReader().cancel(error);
}
else {
callLog.response.body.cancel(error);
}
}

@@ -98,0 +108,0 @@ reject(error);

import glob from 'glob-to-regexp';
import * as regexparam from 'regexparam';
import { isSubsetOf } from 'is-subset-of';
import { isSubsetOf } from './IsSubsetOf.js';
import { dequal as isEqual } from 'dequal';

@@ -114,7 +114,21 @@ import { normalizeHeaders, getPath, normalizeUrl } from './RequestUtils.js';

};
const formDataToObject = (formData) => {
const fields = [...formData];
const result = {};
fields.forEach(([key, value]) => {
result[key] = result[key] || [];
result[key].push(value);
});
return result;
};
const getBodyMatcher = (route) => {
const { body: expectedBody } = route;
let { body: expectedBody } = route;
let expectedBodyType = 'json';
if (!expectedBody) {
return;
}
if (expectedBody instanceof FormData) {
expectedBodyType = 'formData';
expectedBody = formDataToObject(expectedBody);
}
return ({ options: { body, method = 'get' } }) => {

@@ -128,5 +142,14 @@ if (['get', 'head', 'delete'].includes(method.toLowerCase())) {

sentBody = JSON.parse(body);
if (expectedBodyType !== 'json') {
return false;
}
}
}
catch { }
if (body instanceof FormData) {
if (expectedBodyType !== 'formData') {
return false;
}
sentBody = formDataToObject(body);
}
return (sentBody &&

@@ -133,0 +156,0 @@ (route.matchPartialBody

@@ -67,3 +67,8 @@ const absoluteUrlRX = new RegExp('^[a-z]+://|^data:', 'i');

try {
derivedOptions.body = await request.clone().text();
try {
derivedOptions.body = await request.clone().formData();
}
catch {
derivedOptions.body = await request.clone().text();
}
}

@@ -70,0 +75,0 @@ catch { }

@@ -87,6 +87,16 @@ import Route from './Route.js';

if (requestBody instanceof ReadableStream) {
requestBody.cancel(error);
if (requestBody.locked) {
requestBody.getReader().cancel(error);
}
else {
requestBody.cancel(error);
}
}
if (callLog?.response?.body) {
callLog.response.body.cancel(error);
if (callLog.response.body.locked) {
callLog.response.body.getReader().cancel(error);
}
else {
callLog.response.body.cancel(error);
}
}

@@ -93,0 +103,0 @@ reject(error);

3

package.json
{
"name": "fetch-mock",
"description": "Mock http requests made using fetch",
"version": "12.4.0",
"version": "12.5.1",
"exports": {

@@ -27,3 +27,2 @@ "browser": "./dist/esm/index.js",

"glob-to-regexp": "^0.4.1",
"is-subset-of": "^3.1.10",
"regexparam": "^3.0.0"

@@ -30,0 +29,0 @@ },

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