nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: nock/nock
Pull request #2588 (2024-02-13 17:06:01)

fix: fetch response status text
Fix https://github.com/nock/nock/issues/2397#issuecomment-1941125165


Patch:
diff --git a/lib/create_response.js b/lib/create_response.js
index 3884506..3952d4a 100644
--- a/lib/create_response.js
+++ b/lib/create_response.js
@@ -1,6 +1,7 @@
 'use strict'
 
 const { headersArrayToObject } = require('./common')
+const { STATUS_CODES } = require('http')
 
 /**
  * Creates a Fetch API `Response` instance from the given
@@ -37,7 +38,7 @@ function createResponse(message) {
 
   return new Response(responseBodyOrNull, {
     status: message.statusCode,
-    statusText: message.statusMessage,
+    statusText: STATUS_CODES[message.statusCode],
     headers: headersArrayToObject(message.rawHeaders),
   })
 }


Test patch:
diff --git a/tests/test_fetch.js b/tests/test_fetch.js
index fc091c1..25d0b6c 100644
--- a/tests/test_fetch.js
+++ b/tests/test_fetch.js
@@ -90,4 +90,12 @@ describe('Native Fetch', () => {
     const { status } = await fetch('https://example.test')
     expect(status).to.equal(200)
   })
+
+  it('should set the statusText according to the response code', async () => {
+    nock('https://example.test').get('/').reply(404)
+
+    const { status, statusText } = await fetch('https://example.test')
+    expect(status).to.equal(404)
+    expect(statusText).to.equal('Not Found')
+  })
 })
Repository: nock/nock
Pull request #2590 (2024-02-16 16:00:58)

fix: support literal query string
closes https://github.com/nock/nock/issues/2342

@gr2m I'm a bit puzzled here. In the example, it seems like we support this, but we have (an old) test that specifically forbids string as an argument.

Anyway, I think we should support string.


Patch:
diff --git a/lib/interceptor.js b/lib/interceptor.js
index 67ef8b9..aebbdad 100644
--- a/lib/interceptor.js
+++ b/lib/interceptor.js
@@ -510,7 +510,7 @@ module.exports = class Interceptor {
       strFormattingFn = common.percentDecode
     }
 
-    if (queries instanceof URLSearchParams) {
+    if (queries instanceof URLSearchParams || typeof queries === 'string') {
       // Normalize the data into the shape that is matched against.
       // Duplicate keys are handled by combining the values into an array.
       queries = querystring.parse(queries.toString())


Test patch:
diff --git a/tests/got/test_query.js b/tests/got/test_query.js
index 196b147..336a8db 100644
--- a/tests/got/test_query.js
+++ b/tests/got/test_query.js
@@ -19,6 +19,22 @@ describe('query params in path', () => {
 })
 
 describe('`query()`', () => {
+  describe('when called with a string', () => {
+    it('matches a url encoded query string of the same name=value', async () => {
+      const scope = nock('http://example.test')
+        .get('/')
+        .query('foo%5Bbar%5D%3Dhello%20world%21')
+        .reply()
+
+      const { statusCode } = await got(
+        'http://example.test/?foo%5Bbar%5D%3Dhello%20world%21',
+      )
+
+      expect(statusCode).to.equal(200)
+      scope.done()
+    })
+  })
+
   describe('when called with an object', () => {
     it('matches a query string of the same name=value', async () => {
       const scope = nock('http://example.test')
@@ -256,8 +272,8 @@ describe('`query()`', () => {
       const interceptor = nock('http://example.test').get('/')
 
       expect(() => {
-        interceptor.query('foo=bar')
-      }).to.throw(Error, 'Argument Error: foo=bar')
+        interceptor.query(1)
+      }).to.throw(Error, 'Argument Error: 1')
     })
   })
Repository: nock/nock
Pull request #2769 (2024-08-08 22:20:58)

stop forward request headers
This is probably a redundant code from my early work on this PR.


Patch:
diff --git a/lib/intercept.js b/lib/intercept.js
index 0efc216..bf7d14a 100644
--- a/lib/intercept.js
+++ b/lib/intercept.js
@@ -399,14 +399,6 @@ function activate() {
           globalEmitter.emit('no match', nockRequest)
         } else {
           nockRequest.on('response', nockResponse => {
-            // TODO: Consider put empty headers object as default when create the ClientRequest
-            if (nockResponse.req.headers) {
-              // forward Nock request headers to the MSW request
-              Object.entries(nockResponse.req.headers).map(([k, v]) =>
-                mswRequest.headers.set(k, v),
-              )
-            }
-
             const response = createResponse(nockResponse)
             controller.respondWith(response)
           })


Test patch:
diff --git a/tests/test_fetch.js b/tests/test_fetch.js
index f9fdb3a..c78b444 100644
--- a/tests/test_fetch.js
+++ b/tests/test_fetch.js
@@ -119,6 +119,21 @@ describe('Native Fetch', () => {
     scope.done()
   })
 
+  // https://github.com/nock/nock/issues/2768
+  it('should not mess the Headers object', async () => {
+    nock('https://api.test.com', {
+      reqheaders: { 'Content-Type': 'application/json' },
+    })
+      .get('/data')
+      .times(2)
+      .reply(200)
+
+    const headers = new Headers({ 'Content-Type': 'application/json' })
+
+    await fetch('https://api.test.com/data', { headers })
+    await fetch('https://api.test.com/data', { headers })
+  })
+
   describe.skip('content-encoding', () => {
     it('should accept gzipped content', async () => {
       const message = 'Lorem ipsum dolor sit amet'