Comments (4)
This seems to be my problem as well.
Starting from release 13.3.5 (getting rid of lodash) my integration tests started failing.
After some debugging it seems the culprit is the expand function which started to behave differently than before for URLs containing querystring params that are named like object properties e.g. https://www.example.com?q=foo&q.something=bar
.
The following code works fine on 13.3.4, but fails on 13.3.5:
const nock = require('nock');
const fetch = require('node-fetch');
nock('https://www.example.com').get('/').query({ q: 'foo', 'q.something': 'bar' }).reply(200, 'hey');
fetch('https://www.example.com?q=foo&q.something=bar')
.then((res) => res.text())
.then((text) => console.log(text, 'text'));
It's the same story with parameters like q.something
and q[something]
- both used to work just fine until the 13.3.5 release.
from nock.
The fix as a patch for pnpm:
diff --git a/lib/common.js b/lib/common.js
index 97d7c30e4602157b2bf1d475afa6b79525fda606..82ed39892109e51375acf86fa18ca8028796d78d 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -499,7 +499,7 @@ function isStream(obj) {
function normalizeClientRequestArgs(input, options, cb) {
if (typeof input === 'string') {
input = urlToOptions(new url.URL(input))
- } else if (input instanceof url.URL) {
+ } else if (input instanceof url.URL || input.constructor.name === 'URL') {
input = urlToOptions(input)
} else {
cb = options
@@ -731,7 +731,7 @@ const expand = input => {
resultPtr[part] = {}
}
}
- resultPtr = resultPtr[part]
+ resultPtr = { __nock_value: resultPtr[part] }
}
}
}
The first part is a fix for something else (Clickhouse Node JS library doesn't work with nock without this fix as it's uses URLImpl
class for URLs. Checking constructor name worked better in this case).
The second part is fix to always make sure the value is an object.
from nock.
Thanks @bartoszhernas!
Would you mind creating a pull request and adding a test?
from nock.
Two bug fixes with two corresponding tests added to PR.
I realised while writing test, that my original fix was really bad and was hiding the issue and braking URL comparison 🥶
from nock.
Related Issues (20)
- Replace npm debug with require('node:util').debuglog HOT 2
- Remove lodash HOT 1
- Application to become a nock maintainer. HOT 5
- reqheaders does not work when using an undefined requestBody HOT 3
- Add interceptor at the beginning of list
- Return 500 instead of 404 HOT 4
- Bun support for nock.disableNetConnect() HOT 1
- DNS resolve errors and not mocking a lot of requests HOT 7
- POST request with ReadStream request body does not return a response HOT 10
- Disabled discussions HOT 6
- Improve debug logging HOT 2
- Support Abort Signals HOT 1
- Add JSDoc HOT 8
- Using nock inside a stream pipeline with got causes it to hang forever since Node 20.10.0 HOT 2
- Debug logging broken in beta (14.0.0-beta.5) HOT 1
- Error when code cancels fetch response body stream (14.0.0-beta.6) HOT 3
- `fetch` mock does not follow redirect HOT 4
- `i.match is not a function` when `{allowUnmocked: true}` in `14.0.0-beta.7` HOT 5
- [beta] ENETUNREACH escape error handling when using native node fetch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nock.