🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

nock

Package Overview
Dependencies
Maintainers
4
Versions
445
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nock - npm Package Compare versions

Comparing version

to
14.0.0-beta.19

6

package.json

@@ -10,3 +10,3 @@ {

],
"version": "14.0.0-beta.18",
"version": "14.0.0-beta.19",
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",

@@ -26,3 +26,3 @@ "repository": {

"dependencies": {
"@mswjs/interceptors": "^0.36.6",
"@mswjs/interceptors": "^0.37.3",
"json-stringify-safe": "^5.0.1",

@@ -53,3 +53,3 @@ "propagate": "^2.0.0"

"rimraf": "^3.0.0",
"semantic-release": "^22.0.5",
"semantic-release": "^24.1.0",
"sinon": "^17.0.1",

@@ -56,0 +56,0 @@ "sinon-chai": "^3.7.0",

@@ -10,10 +10,2 @@ # Nock

> **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

@@ -696,42 +688,13 @@

.get('/')
.delay(2000) // 2 seconds delay will be applied to the response header.
.delay(2000) // 2 seconds delay will be applied to the response body.
.reply(200, '<html></html>')
```
`delay(1000)` is an alias for `delayConnection(1000).delayBody(0)`
`delay({ head: 1000, body: 2000 })` is an alias for `delayConnection(1000).delayBody(2000)`
Both of which are covered in detail below.
#### Delay the connection
You are able to specify the number of milliseconds that your connection should be idle before it starts to receive the response.
The `delayConnection` method’s behavior of emitting quick timeout events when the connection delay exceeds the request timeout is now deprecated. Please use the `delay` function instead.
To simulate a socket timeout, provide a larger value than the timeout setting on the request.
```js
nock('http://my.server.com')
.get('/')
.delayConnection(2000) // 2 seconds
.reply(200, '<html></html>')
req = http.request('http://my.server.com', { timeout: 1000 })
```
Nock emits timeout events almost immediately by comparing the requested connection delay to the timeout parameter passed to `http.request()` or `http.ClientRequest#setTimeout()`.
This allows you to test timeouts without using fake timers or slowing down your tests.
If the client chooses to _not_ take an action (e.g. abort the request), the request and response will continue on as normal, after real clock time has passed.
##### Technical Details
Following the `'finish'` event being emitted by `ClientRequest`, Nock will wait for the next event loop iteration before checking if the request has been aborted.
At this point, any connection delay value is compared against any request timeout setting and a [`'timeout'`](https://nodejs.org/api/http.html#http_event_timeout) is emitted when appropriate from the socket and the request objects.
A Node timeout timer is then registered with any connection delay value to delay real time before checking again if the request has been aborted and the [`'response'`](http://nodejs.org/api/http.html#http_event_response) is emitted by the request.
A similar method, `.socketDelay()` was removed in version 13. It was thought that having two methods so subtlety similar was confusing.
The discussion can be found at https://github.com/nock/nock/pull/1974.
#### Delay the response body
You are able to specify the number of milliseconds that the response body should be delayed.
This is the time between the headers being received and the body starting to be received.
The `delayBody` is now deprecated. Please use the `delay` function instead.

@@ -738,0 +701,0 @@ ```js

@@ -208,4 +208,9 @@ // TypeScript Version: 3.5

delay(opts: number): this
/** @deprecated use delay(number) instead */
delay(opts: { head?: number; body?: number }): this
delay(opts: number | { head?: number; body?: number }): this
/** @deprecated use delay function instead */
delayBody(timeMs: number): this
/** @deprecated use delay function instead */
delayConnection(timeMs: number): this

@@ -260,3 +265,3 @@ }

options: BackOptions,
nockedFn: (nockDone: () => Promise<void>) => void,
nockedFn: (nockDone: () => void) => void,
): void

@@ -267,3 +272,3 @@ (

): Promise<{
nockDone: () => Promise<void>
nockDone: () => void
context: BackContext

@@ -295,3 +300,3 @@ }>

after?: (scope: Scope) => void
afterRecord?: (defs: Definition[]) => Definition[]
afterRecord?: (defs: Definition[]) => Definition[] | string
recorder?: RecorderOptions

@@ -298,0 +303,0 @@ }