nock: incompatible behaviour introduced with v13.3.2
Please avoid duplicates
- I checked all open bugs and none of them matched my problem.
Reproducible test case
Code snipped added to “What happened?”
Nock Version
v13.3.2
Node Version
18.15.0
TypeScript Version
No response
What happened?
Hi dear nock-team,
with commit https://github.com/nock/nock/commit/8aab603f2b884f49618fbfdcc3c9529cccdc8975 a new breaking change/behaviour has been introduced which crashes our tests of several projects. It is reordering the interceptors which leads to a different sequence handling.
'use strict';
// Console with nock 13.3.2 (incorrect)
// special file
// all others
// all others
//
// Console with nock 13.3.1 (correct)
// special file
// special file
// all others
const https = require('https');
const nock = require('nock');
nock.back.setMode('lockdown');
const get = uri => {
return new Promise(resolve => {
https.get(uri, res => {
const data = [];
res.on('data', chunk => data.push(chunk));
res.on('end', () => resolve(Buffer.concat(data).toString()));
});
});
};
(async() => {
nock("https://test.com")
.persist()
.get("/special-file.json").reply(200, "special file")
.get(/.*/).reply(200, "all others");
console.log(await get("https://test.com/special-file.json"));
console.log(await get("https://test.com/special-file.json"));
console.log(await get("https://test.com/other-file.json"));
})();
Would you be interested in contributing a fix?
- yes
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
Commits related to this issue
- fix: revert #2497 (`nock.removeInterceptor` can remove the wrong Intercept) This reverts commit 92de0debdaccdb27d002f6d6ebb80e430d3808ce. See https://github.com/nock/nock/issues/2500 — committed to nock/nock by gr2m 10 months ago
- fix: revert #2350 (Push persisted interceptors to the end instead of ignore on remove) This reverts commit 8aab603f2b884f49618fbfdcc3c9529cccdc8975. See #2500 — committed to nock/nock by gr2m 10 months ago
- fix: revert #2350 (Push persisted interceptors to the end instead of ignore on remove) (#2511) This reverts commit 8aab603f2b884f49618fbfdcc3c9529cccdc8975. See #2500 — committed to nock/nock by gr2m 10 months ago
Shall we do this then?