nock 14.0.2 → 14.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/intercept.js +13 -2
- package/package.json +2 -2
package/lib/intercept.js
CHANGED
|
@@ -10,12 +10,13 @@ const { inherits } = require('util')
|
|
|
10
10
|
const http = require('http')
|
|
11
11
|
const { intercept: debug } = require('./debug')
|
|
12
12
|
const globalEmitter = require('./global_emitter')
|
|
13
|
-
const { BatchInterceptor } = require('@mswjs/interceptors')
|
|
13
|
+
const { BatchInterceptor, getRawRequest } = require('@mswjs/interceptors')
|
|
14
14
|
const {
|
|
15
15
|
default: nodeInterceptors,
|
|
16
16
|
} = require('@mswjs/interceptors/presets/node')
|
|
17
17
|
const { createResponse } = require('./create_response')
|
|
18
18
|
const { once } = require('events')
|
|
19
|
+
const { arrayBuffer } = require('stream/consumers')
|
|
19
20
|
|
|
20
21
|
const interceptor = new BatchInterceptor({
|
|
21
22
|
name: 'nock-interceptor',
|
|
@@ -409,7 +410,17 @@ function activate() {
|
|
|
409
410
|
once(nockRequest, 'error'),
|
|
410
411
|
once(nockRequest, 'response'),
|
|
411
412
|
])
|
|
412
|
-
|
|
413
|
+
|
|
414
|
+
const rawRequest = getRawRequest(mswRequest)
|
|
415
|
+
|
|
416
|
+
// If this is GET request with body, we need to read the body from the socket because Fetch API doesn't support this.
|
|
417
|
+
const buffer =
|
|
418
|
+
rawRequest instanceof originalClientRequest &&
|
|
419
|
+
rawRequest.method === 'GET' &&
|
|
420
|
+
rawRequest.getHeader('content-length') > 0
|
|
421
|
+
? // TODO: use getClientRequestBodyStream instead of access to internal properties
|
|
422
|
+
await arrayBuffer(rawRequest.socket.requestStream)
|
|
423
|
+
: await request.arrayBuffer()
|
|
413
424
|
nockRequest.write(buffer)
|
|
414
425
|
nockRequest.end()
|
|
415
426
|
await promise
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "14.0.
|
|
10
|
+
"version": "14.0.4",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"main": "./index.js",
|
|
23
23
|
"types": "types",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@mswjs/interceptors": "^0.38.
|
|
25
|
+
"@mswjs/interceptors": "^0.38.5",
|
|
26
26
|
"json-stringify-safe": "^5.0.1",
|
|
27
27
|
"propagate": "^2.0.0"
|
|
28
28
|
},
|