From f4d1b15d8ef64ae6d8c0e6d7c62324a19f138b5f Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:17:28 -0800 Subject: [PATCH 1/6] ci(test): use a single `test` job that we can require, independent of test matrix (#2581) --- .github/workflows/continuous-integration.yaml | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 45dcc8d08..630d7586a 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -63,9 +63,26 @@ jobs: - name: Lint run: | npm run lint:ts - test: - name: Test + + # verify against ranges defined as supported in engines.node + test_matrix: + strategy: + fail-fast: false + matrix: + node-version: + - 10 + - 12 + - 14 + - 16 + - 18 + os: + - macos-latest + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} + timeout-minutes: 5 + steps: - name: Checkout uses: actions/checkout@v4 @@ -83,16 +100,18 @@ jobs: - name: Test jest run: npm run test:jest if: matrix.node-version >= 14 - strategy: - fail-fast: false - matrix: - node-version: - - 10 - - 12 - - 14 - - 16 - - 18 - os: - - macos-latest - - ubuntu-latest - - windows-latest + + # separate job to set as required in branch protection, + # as the build names above change each time Node versions change + test: + runs-on: ubuntu-latest + needs: + - test_matrix + if: ${{ !cancelled() }} + steps: + - name: All matrix versions passed + if: ${{ !(contains(needs.*.result, 'failure')) }} + run: exit 0 + - name: Some matrix version failed + if: ${{ contains(needs.*.result, 'failure') }} + run: exit 1 From 4ad60ba76a051d41640eb04a5df21dabed7f6b65 Mon Sep 17 00:00:00 2001 From: Michael Solomon Date: Tue, 6 Feb 2024 23:57:23 +0200 Subject: [PATCH 2/6] add experimental fetch support notice (#2583) --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e26ecaf89..28552bb98 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,13 @@ [npmjs]: https://www.npmjs.com/package/nock [build]: https://travis-ci.org/nock/nock -> **Warning** -> nock is currently not compatible with Node's experimental native `fetch` implementation. See [#2397](https://github.com/nock/nock/issues/2397) +> **Notice** +> +> We have introduced experimental support for fetch. Please share your feedback with us. You can install it by: +> +> ``` +> npm install --save-dev nock@beta +> ``` HTTP server mocking and expectations library for Node.js From 8deca36315f17bbc9ee1b0e4274b8f43e6234ccb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:46:02 -0800 Subject: [PATCH 3/6] docs: add mikicho as a contributor for maintenance, code, and doc (#2584) --- .all-contributorsrc | 11 +++++++++++ README.md | 1 + 2 files changed, 12 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index a2511741c..4bd7f412b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -157,6 +157,17 @@ "code", "test" ] + }, + { + "login": "mikicho", + "name": "Michael Solomon", + "avatar_url": "https://avatars.githubusercontent.com/u/11459632?v=4", + "profile": "https://github.com/mikicho", + "contributions": [ + "maintenance", + "code", + "doc" + ] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index 28552bb98..43f1eaaaf 100644 --- a/README.md +++ b/README.md @@ -1703,6 +1703,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri Saryev Rustam
Saryev Rustam

💻 ⚠️ + Michael Solomon
Michael Solomon

🚧 💻 📖 From 8bab28daa07c53ebe69db479c2a9a7551b864039 Mon Sep 17 00:00:00 2001 From: Vladimir Chuprazov <82871772+VladimirChuprazov@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:16:36 +0100 Subject: [PATCH 4/6] ci: add node 20 in ci (#2585) --- .github/workflows/continuous-integration.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 630d7586a..c4c6fccfc 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -75,6 +75,7 @@ jobs: - 14 - 16 - 18 + - 20 os: - macos-latest - ubuntu-latest From 7e957b38fbc797f1c3480f1de8e0659f9998cdc3 Mon Sep 17 00:00:00 2001 From: Maxime Bargiel Date: Sat, 17 Feb 2024 13:17:33 -0500 Subject: [PATCH 5/6] fix: remove duplicates from `activeMocks()` and `pendingMocks()` (#2356) --- lib/intercept.js | 3 ++- tests/got/test_nock_lifecycle.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/intercept.js b/lib/intercept.js index cf266d5a5..bcc1319ce 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -350,7 +350,8 @@ function interceptorScopes() { const nestedInterceptors = Object.values(allInterceptors).map( i => i.interceptors, ) - return [].concat(...nestedInterceptors).map(i => i.scope) + const scopes = new Set([].concat(...nestedInterceptors).map(i => i.scope)) + return [...scopes] } function isDone() { diff --git a/tests/got/test_nock_lifecycle.js b/tests/got/test_nock_lifecycle.js index 92a07efe8..622f3076b 100644 --- a/tests/got/test_nock_lifecycle.js +++ b/tests/got/test_nock_lifecycle.js @@ -163,6 +163,22 @@ describe('Nock lifecycle functions', () => { await got('http://example.test/') expect(nock.activeMocks()).to.be.empty() }) + + it("activeMocks doesn't return duplicate mocks", () => { + nock('http://example.test') + .get('/') + .reply() + .get('/second') + .reply() + .get('/third') + .reply() + + expect(nock.activeMocks()).to.deep.equal([ + 'GET http://example.test:80/', + 'GET http://example.test:80/second', + 'GET http://example.test:80/third', + ]) + }) }) describe('resetting nock catastrophically while a request is in progress', () => { From 4162fa8b2ddaf6a3c5b52162b03629118236847f Mon Sep 17 00:00:00 2001 From: Michael Solomon Date: Sat, 17 Feb 2024 20:38:55 +0200 Subject: [PATCH 6/6] fix: support literal query string (#2590) --- lib/interceptor.js | 2 +- tests/got/test_query.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/interceptor.js b/lib/interceptor.js index 67ef8b946..aebbdad14 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()) diff --git a/tests/got/test_query.js b/tests/got/test_query.js index 196b14783..336a8dbc9 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') }) })