nock: incompatible behaviour introduced with v13.3.2

Please avoid duplicates

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

Most upvoted comments

Shall we do this then?

  1. Create PR to revert the change of v13.3.2
  2. Create PR that adds a test that will prevent the same regression from happening again