Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/prettier-3.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicho committed Feb 26, 2024
2 parents 65e80e3 + 4162fa8 commit df9d584
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 21 deletions.
11 changes: 11 additions & 0 deletions .all-contributorsrc
Expand Up @@ -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,
Expand Down
50 changes: 35 additions & 15 deletions .github/workflows/continuous-integration.yaml
Expand Up @@ -63,9 +63,27 @@ 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
- 20
os:
- macos-latest
- ubuntu-latest
- windows-latest

runs-on: ${{ matrix.os }}
timeout-minutes: 5

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -83,16 +101,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
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -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

Expand Down Expand Up @@ -1698,6 +1703,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rsaryev"><img src="https://avatars.githubusercontent.com/u/70219513?v=4?s=100" width="100px;" alt="Saryev Rustam"/><br /><sub><b>Saryev Rustam</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=rsaryev" title="Code">💻</a> <a href="https://github.com/nock/nock/commits?author=rsaryev" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mikicho"><img src="https://avatars.githubusercontent.com/u/11459632?v=4?s=100" width="100px;" alt="Michael Solomon"/><br /><sub><b>Michael Solomon</b></sub></a><br /><a href="#maintenance-mikicho" title="Maintenance">🚧</a> <a href="https://github.com/nock/nock/commits?author=mikicho" title="Code">💻</a> <a href="https://github.com/nock/nock/commits?author=mikicho" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
3 changes: 2 additions & 1 deletion lib/intercept.js
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion lib/interceptor.js
Expand Up @@ -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())
Expand Down
16 changes: 16 additions & 0 deletions tests/got/test_nock_lifecycle.js
Expand Up @@ -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', () => {
Expand Down
20 changes: 18 additions & 2 deletions tests/got/test_query.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
})
})

Expand Down

0 comments on commit df9d584

Please sign in to comment.