Update checked-in dependencies

This commit is contained in:
github-actions[bot]
2025-07-28 22:01:01 +00:00
parent 264ce42cbb
commit 12e4b97fba
5 changed files with 118 additions and 26 deletions

81
node_modules/nock/README.md generated vendored
View File

@@ -91,6 +91,7 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
- [Requests made by ES Modules are not intercepted](#requests-made-by-es-modules-are-not-intercepted)
- [Axios](#axios)
- [Memory issues with Jest](#memory-issues-with-jest)
- [Fake timers](#fake-timers)
- [Debugging](#debugging)
- [Contributing](#contributing)
- [Contributors](#contributors)
@@ -1613,6 +1614,86 @@ One of the core principles of [Jest](https://jestjs.io/) is that it runs tests i
It does this by manipulating the modules cache of Node in a way that conflicts with how Nock monkey patches the builtin `http` and `https` modules.
[Related issue with more details](https://github.com/nock/nock/issues/1817).
### Fake timers
### Jest
To use `nock` in conjunction with `jest` fake timers, make sure you're using the "async" functions when advancing the
timers, such as `jest.advanceTimersByTimeAsync()` or `jest.runAllTimersAsync()`. Otherwise, the timers will not be
advanced correctly and you'll experience a timeout in your tests.
```js
test('should mock a request with fake timers', async () => {
jest.useFakeTimers()
const scope = nock('https://example.com')
.get('/path')
.delay(1000)
.reply(200, 'response')
// Simulate a request
const request = got('https://example.com/path')
// Fast-forward time
await jest.advanceTimersByTimeAsync(1000)
// Or advance all timers
await jest.runAllTimersAsync()
// Wait for the request to complete
const response = await request
expect(response.body).toBe('response')
jest.useRealTimers() // Restore real timers after the test
scope.done()
})
```
In case you don't need testing delays, you can instruct `jest` to advance the timers automatically using the
`advanceTimers` option
```js
jest.useFakeTimers({ advanceTimers: true })
```
### Sinon
In a similar way to `jest`, if you are using `sinon` fake timers, you should use the `clock.tickAsync()` or
`clock.runAllAsync()` methods to advance the timers correctly.
```js
it('should us sinon timers', async () => {
clock = sinon.useFakeTimers()
const scope = nock('https://example.com')
.get('/path')
.delay(1000)
.reply(200, 'response')
// Simulate a request
const request = got('https://example.com/path')
// Fast-forward time
await clock.tickAsync(1000)
// Or run all timers
await clock.runAllAsync()
// Wait for the request to complete
const response = await request
expect(response.body).toBe('response')
clock.restore()
scope.done()
})
```
Same applies for `sinon`, if you don't need testing delays, you can instruct `sinon` to advance the timers automatically
using the `shouldAdvanceTime` option
```js
clock = sinon.useFakeTimers({ shouldAdvanceTime: true })
```
## Debugging
Nock uses node internals [`debuglog`](https://nodejs.org/api/util.html#utildebuglogsection-callbackg), so just run with environmental variable `NODE_DEBUG` set to `nock:*`.