fetch-mock
Advanced tools
Comparing version
{ | ||
"name": "fetch-mock", | ||
"version": "10.0.8-alpha.1", | ||
"version": "10.0.8", | ||
"description": "Mock http requests made using fetch (or isomorphic-fetch)", | ||
@@ -14,13 +14,6 @@ "main": "./dist/commonjs.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "make lint test", | ||
"prepublishOnly": "make build" | ||
}, | ||
"funding": { | ||
"type": "charity", | ||
"url": "https://www.justgiving.com/refugee-support-europe" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wheresrhys/fetch-mock.git" | ||
"url": "git+https://github.com/wheresrhys/fetch-mock.git", | ||
"directory": "packages/fetch-mock" | ||
}, | ||
@@ -47,4 +40,3 @@ "keywords": [ | ||
"lodash.isequal": "^4.5.0", | ||
"path-to-regexp": "^2.2.1", | ||
"querystring": "^0.2.1" | ||
"path-to-regexp": "^2.2.1" | ||
}, | ||
@@ -58,26 +50,3 @@ "peerDependenciesMeta": { | ||
"node": ">=4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@vitest/browser": "^1.1.0", | ||
"@vitest/coverage-istanbul": "^1.1.0", | ||
"dtslint": "^1.0.2", | ||
"eslint": "^8.56.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-origami-component": "^2.2.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prettier": "^5.1.2", | ||
"jest": "^29.7.0", | ||
"jsdom": "^23.0.1", | ||
"prettier": "^3.1.1", | ||
"rollup": "^4.9.1", | ||
"typescript": "^3.6.4", | ||
"vitest": "^1.1.0", | ||
"webdriverio": "^8.27.0" | ||
}, | ||
"volta": { | ||
"node": "18.19.0" | ||
} | ||
} |
@@ -166,3 +166,2 @@ import { getDebug } from './debug.js'; | ||
apply: (func, thisArg, args) => { | ||
this.debug(`Calling res.${name}`); | ||
const result = func.apply(response, args); | ||
@@ -169,0 +168,0 @@ if (result.then) { |
import glob from 'glob-to-regexp'; | ||
import pathToRegexp from 'path-to-regexp'; | ||
import querystring from 'querystring'; | ||
import isSubset from 'is-subset'; | ||
@@ -81,18 +80,50 @@ import isEqual from 'lodash.isequal'; | ||
} | ||
const expectedQuery = querystring.parse(querystring.stringify(passedQuery)); | ||
debug(' Expected query parameters:', passedQuery); | ||
const keys = Object.keys(expectedQuery); | ||
const expectedQuery = new URLSearchParams(); | ||
for (const [key, value] of Object.entries(passedQuery)) { | ||
if (Array.isArray(value)) { | ||
for (const item of value) { | ||
expectedQuery.append( | ||
key, | ||
typeof item === 'object' || typeof item === 'undefined' | ||
? '' | ||
: item.toString(), | ||
); | ||
} | ||
} else { | ||
expectedQuery.append( | ||
key, | ||
typeof value === 'object' || typeof value === 'undefined' | ||
? '' | ||
: value.toString(), | ||
); | ||
} | ||
} | ||
const keys = Array.from(expectedQuery.keys()); | ||
return (url) => { | ||
debug('Attempting to match query parameters'); | ||
const query = querystring.parse(getQuery(url)); | ||
debug(' Expected query parameters:', expectedQuery); | ||
debug(' Actual query parameters:', query); | ||
const queryString = getQuery(url); | ||
const query = new URLSearchParams(queryString); | ||
debug( | ||
' Expected query parameters:', | ||
Object.fromEntries(expectedQuery.entries()), | ||
); | ||
debug(' Actual query parameters:', Object.fromEntries(query.entries())); | ||
return keys.every((key) => { | ||
if (Array.isArray(query[key])) { | ||
if (!Array.isArray(expectedQuery[key])) { | ||
return false; | ||
} | ||
return isEqual(query[key].sort(), expectedQuery[key].sort()); | ||
const expectedValues = expectedQuery.getAll(key).sort(); | ||
const actualValues = query.getAll(key).sort(); | ||
if (expectedValues.length !== actualValues.length) { | ||
return false; | ||
} | ||
return query[key] === expectedQuery[key]; | ||
if (Array.isArray(passedQuery[key])) { | ||
return expectedValues.every( | ||
(expected, index) => expected === actualValues[index], | ||
); | ||
} | ||
return isEqual(actualValues, expectedValues); | ||
}); | ||
@@ -99,0 +130,0 @@ }; |
@@ -13,4 +13,4 @@ // Project: https://github.com/wheresrhys/fetch-mock, http://www.wheresrhys.co.uk/fetch-mock | ||
// | ||
// Please note that I - wheresrys - don't use Typescript | ||
// These types have ben copied in here as a convenience for (some of) | ||
// Please note that I - wheresrhys - don't use Typescript | ||
// These types have been copied in here as a convenience for (some of) | ||
// fetch-mock's users | ||
@@ -620,2 +620,7 @@ // If you are a Typescript user and find a problem in these types, please | ||
statusTextMap: { | ||
[key: number]: string | ||
} | ||
config: { | ||
@@ -622,0 +627,0 @@ /** |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
224885
1.16%5
-16.67%0
-100%6852
1.98%0
-100%- Removed
- Removed