nock 15.0.0 → 15.0.1

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.
Files changed (40) hide show
  1. package/README.md +39 -0
  2. package/dist/index.d.ts +60 -0
  3. package/dist/index.js +109 -0
  4. package/dist/lib/back.d.ts +44 -0
  5. package/{lib → dist/lib}/back.js +111 -84
  6. package/dist/lib/common.d.ts +27 -0
  7. package/{lib → dist/lib}/common.js +80 -190
  8. package/dist/lib/debug.d.ts +9 -0
  9. package/dist/lib/debug.js +17 -0
  10. package/dist/lib/global_emitter.d.ts +11 -0
  11. package/dist/lib/global_emitter.js +13 -0
  12. package/dist/lib/handle-request.d.ts +2 -0
  13. package/{lib → dist/lib}/handle-request.js +24 -39
  14. package/dist/lib/intercept.d.ts +25 -0
  15. package/{lib → dist/lib}/intercept.js +81 -94
  16. package/dist/lib/interceptor.d.ts +44 -0
  17. package/{lib → dist/lib}/interceptor.js +223 -119
  18. package/dist/lib/interceptors/builtin.d.ts +3 -0
  19. package/dist/lib/interceptors/builtin.js +56 -0
  20. package/dist/lib/match_body.d.ts +1 -0
  21. package/{lib → dist/lib}/match_body.js +20 -27
  22. package/dist/lib/playback_interceptor.d.ts +8 -0
  23. package/{lib → dist/lib}/playback_interceptor.js +52 -62
  24. package/dist/lib/recorder.d.ts +13 -0
  25. package/{lib → dist/lib}/recorder.js +63 -92
  26. package/dist/lib/scope.d.ts +59 -0
  27. package/{lib → dist/lib}/scope.js +158 -87
  28. package/dist/lib/stringify.d.ts +24 -0
  29. package/dist/lib/stringify.js +50 -0
  30. package/dist/lib/utils/node/index.d.ts +4 -0
  31. package/dist/lib/utils/node/index.js +16 -0
  32. package/package.json +25 -22
  33. package/index.js +0 -55
  34. package/lib/create_response.js +0 -53
  35. package/lib/debug.js +0 -12
  36. package/lib/global_emitter.js +0 -5
  37. package/lib/interceptors/builtin.js +0 -67
  38. package/lib/interceptors/undici.js +0 -78
  39. package/lib/utils/node/index.js +0 -33
  40. package/types/index.d.ts +0 -319
@@ -0,0 +1,59 @@
1
+ import type { ReplyBody, ReplyHeaders, RequestBodyMatcher, RequestHeaderMatcher } from './interceptor.ts';
2
+ export interface Options {
3
+ allowUnmocked?: boolean;
4
+ reqheaders?: Record<string, RequestHeaderMatcher>;
5
+ badheaders?: string[];
6
+ conditionally?: () => boolean;
7
+ filteringScope?: (scope: string) => boolean;
8
+ encodedQueryParams?: boolean;
9
+ }
10
+ export interface Definition {
11
+ scope: string | RegExp;
12
+ path: string | RegExp;
13
+ port?: number | string;
14
+ method?: string;
15
+ status?: number;
16
+ body?: RequestBodyMatcher;
17
+ reply?: string;
18
+ reqheaders?: Record<string, RequestHeaderMatcher>;
19
+ badheaders?: string[];
20
+ rawHeaders?: ReplyHeaders;
21
+ response?: ReplyBody;
22
+ responseIsBinary?: boolean;
23
+ headers?: ReplyHeaders;
24
+ options?: Options;
25
+ }
26
+ import { EventEmitter } from 'node:events';
27
+ import { Interceptor } from './interceptor.ts';
28
+ declare class Scope extends EventEmitter {
29
+ constructor(basePath: string | RegExp | URL, options?: Options);
30
+ add(key: string, interceptor: Interceptor): void;
31
+ remove(key: string, interceptor: Interceptor): void;
32
+ intercept(uri: string | RegExp | ((path: string) => boolean), method: string, requestBody?: RequestBodyMatcher, interceptorOptions?: Options): Interceptor;
33
+ get(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
34
+ post(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
35
+ put(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
36
+ head(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
37
+ patch(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
38
+ merge(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
39
+ delete(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
40
+ options(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
41
+ pendingMocks(): string[];
42
+ activeMocks(): string[];
43
+ isDone(): boolean;
44
+ done(): void;
45
+ buildFilter(): any;
46
+ filteringPath(): this;
47
+ filteringRequestBody(): this;
48
+ matchHeader(name: string, value: RequestHeaderMatcher): this;
49
+ defaultReplyHeaders(headers: ReplyHeaders): this;
50
+ persist(flag?: boolean): this;
51
+ shouldPersist(): boolean;
52
+ replyContentLength(): this;
53
+ replyDate(d?: Date): this;
54
+ clone(): Scope;
55
+ }
56
+ declare function loadDefs(path: string): any;
57
+ declare function load(path: string): Scope[];
58
+ declare function define(nockDefs: Record<string, any>[]): Scope[];
59
+ export { Scope, load, loadDefs, define };
@@ -1,21 +1,45 @@
1
- 'use strict'
2
-
3
- /**
4
- * @module nock/scope
5
- */
6
- const fs = require('node:fs')
7
- const { scopeDebuglog } = require('./debug')
8
- const { addInterceptor, isOn } = require('./intercept')
9
- const common = require('./common')
10
- const assert = require('node:assert')
11
- const { EventEmitter } = require('node:events')
12
- const Interceptor = require('./interceptor')
13
-
14
- /**
15
- * Normalizes the passed url for consistent internal processing
16
- * @param {string|URL} u
17
- */
18
- function normalizeUrl(u) {
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ import fs from 'node:fs'
35
+ import { scopeDebuglog } from './debug.js'
36
+ import { addInterceptor, isOn } from './intercept.js'
37
+ import * as common from './common.js'
38
+ import assert from 'node:assert'
39
+ import { EventEmitter } from 'node:events'
40
+ import { Interceptor } from './interceptor.js'
41
+
42
+ function normalizeUrl(u ) {
19
43
  if (typeof u === 'string') {
20
44
  // If the url is invalid, let the URL library report it
21
45
  return normalizeUrl(new URL(u))
@@ -47,19 +71,41 @@ function normalizeUrl(u) {
47
71
  }
48
72
  }
49
73
 
50
- /**
51
- * @param {string|RegExp|URL} basePath
52
- * @param {Object} options
53
- * @param {boolean} options.allowUnmocked
54
- * @param {string[]} options.badheaders
55
- * @param {function} options.conditionally
56
- * @param {boolean} options.encodedQueryParams
57
- * @param {function} options.filteringScope
58
- * @param {Object} options.reqheaders
59
- * @constructor
60
- */
61
74
  class Scope extends EventEmitter {
62
- constructor(basePath, options) {
75
+ /** @internal */
76
+
77
+ /** @internal */
78
+
79
+ /** @internal */
80
+
81
+ /** @internal */
82
+
83
+
84
+
85
+ /** @internal */
86
+
87
+ /** @internal */
88
+
89
+ /** @internal */
90
+
91
+ /** @internal */
92
+
93
+ /** @internal */
94
+
95
+ /** @internal */
96
+
97
+ /** @internal */
98
+
99
+ /** @internal */
100
+
101
+ /** @internal */
102
+
103
+ /** @internal */
104
+
105
+ /** @internal */
106
+
107
+
108
+ constructor(basePath , options ) {
63
109
  super()
64
110
 
65
111
  this.keyedInterceptors = {}
@@ -72,7 +118,7 @@ class Scope extends EventEmitter {
72
118
  this._persist = false
73
119
  this.contentLen = false
74
120
  this.date = null
75
- this.basePath = basePath
121
+ this.basePath = basePath
76
122
  this.basePathname = ''
77
123
  this.port = null
78
124
  this._defaultReplyHeaders = []
@@ -80,7 +126,7 @@ class Scope extends EventEmitter {
80
126
  let logNamespace = String(basePath)
81
127
 
82
128
  if (!(basePath instanceof RegExp)) {
83
- this.urlParts = normalizeUrl(basePath)
129
+ this.urlParts = normalizeUrl(basePath )
84
130
  this.port = this.urlParts.port
85
131
  this.basePathname = this.urlParts.pathname.replace(/\/$/, '')
86
132
  this.basePath = `${this.urlParts.protocol}//${this.urlParts.hostname}:${this.port}`
@@ -90,21 +136,21 @@ class Scope extends EventEmitter {
90
136
  this.logger = scopeDebuglog(logNamespace)
91
137
  }
92
138
 
93
- add(key, interceptor) {
139
+ add(key , interceptor ) {
94
140
  if (!(key in this.keyedInterceptors)) {
95
141
  this.keyedInterceptors[key] = []
96
142
  }
97
143
  this.keyedInterceptors[key].push(interceptor)
98
144
  addInterceptor(
99
- this.basePath,
145
+ this.basePath ,
100
146
  interceptor,
101
147
  this,
102
148
  this.scopeOptions,
103
- this.urlParts.hostname,
149
+ this.urlParts.hostname ,
104
150
  )
105
151
  }
106
152
 
107
- remove(key, interceptor) {
153
+ remove(key , interceptor ) {
108
154
  if (this._persist) {
109
155
  return
110
156
  }
@@ -117,7 +163,12 @@ class Scope extends EventEmitter {
117
163
  }
118
164
  }
119
165
 
120
- intercept(uri, method, requestBody, interceptorOptions) {
166
+ intercept(
167
+ uri ,
168
+ method ,
169
+ requestBody ,
170
+ interceptorOptions ,
171
+ ) {
121
172
  const ic = new Interceptor(
122
173
  this,
123
174
  uri,
@@ -130,53 +181,83 @@ class Scope extends EventEmitter {
130
181
  return ic
131
182
  }
132
183
 
133
- get(uri, requestBody, options) {
184
+ get(
185
+ uri ,
186
+ requestBody ,
187
+ options ,
188
+ ) {
134
189
  return this.intercept(uri, 'GET', requestBody, options)
135
190
  }
136
191
 
137
- post(uri, requestBody, options) {
192
+ post(
193
+ uri ,
194
+ requestBody ,
195
+ options ,
196
+ ) {
138
197
  return this.intercept(uri, 'POST', requestBody, options)
139
198
  }
140
199
 
141
- put(uri, requestBody, options) {
200
+ put(
201
+ uri ,
202
+ requestBody ,
203
+ options ,
204
+ ) {
142
205
  return this.intercept(uri, 'PUT', requestBody, options)
143
206
  }
144
207
 
145
- head(uri, requestBody, options) {
208
+ head(
209
+ uri ,
210
+ requestBody ,
211
+ options ,
212
+ ) {
146
213
  return this.intercept(uri, 'HEAD', requestBody, options)
147
214
  }
148
215
 
149
- patch(uri, requestBody, options) {
216
+ patch(
217
+ uri ,
218
+ requestBody ,
219
+ options ,
220
+ ) {
150
221
  return this.intercept(uri, 'PATCH', requestBody, options)
151
222
  }
152
223
 
153
- merge(uri, requestBody, options) {
224
+ merge(
225
+ uri ,
226
+ requestBody ,
227
+ options ,
228
+ ) {
154
229
  return this.intercept(uri, 'MERGE', requestBody, options)
155
230
  }
156
231
 
157
- delete(uri, requestBody, options) {
232
+ delete(
233
+ uri ,
234
+ requestBody ,
235
+ options ,
236
+ ) {
158
237
  return this.intercept(uri, 'DELETE', requestBody, options)
159
238
  }
160
239
 
161
- options(uri, requestBody, options) {
240
+ options(
241
+ uri ,
242
+ requestBody ,
243
+ options ,
244
+ ) {
162
245
  return this.intercept(uri, 'OPTIONS', requestBody, options)
163
246
  }
164
247
 
165
248
  // Returns the list of keys for non-optional Interceptors that haven't been completed yet.
166
- // TODO: This assumes that completed mocks are removed from the keyedInterceptors list
167
- // (when persistence is off). We should change that (and this) in future.
168
249
  pendingMocks() {
169
- return this.activeMocks().filter(key =>
170
- this.keyedInterceptors[key].some(({ interceptionCounter, optional }) => {
171
- const persistedAndUsed = this._persist && interceptionCounter > 0
172
- return !persistedAndUsed && !optional
173
- }),
250
+ return this.activeMocks().filter((key ) =>
251
+ this.keyedInterceptors[key].some(
252
+ ({ interceptionCounter, optional } ) => {
253
+ const persistedAndUsed = this._persist && interceptionCounter > 0
254
+ return !persistedAndUsed && !optional
255
+ },
256
+ ),
174
257
  )
175
258
  }
176
259
 
177
260
  // Returns all keyedInterceptors that are active.
178
- // This includes incomplete interceptors, persisted but complete interceptors, and
179
- // optional interceptors, but not non-persisted and completed interceptors.
180
261
  activeMocks() {
181
262
  return Object.keys(this.keyedInterceptors)
182
263
  }
@@ -197,16 +278,12 @@ class Scope extends EventEmitter {
197
278
  }
198
279
 
199
280
  buildFilter() {
200
- const filteringArguments = arguments
281
+ const filteringArguments = Array.from(arguments)
201
282
 
202
283
  if (arguments[0] instanceof RegExp) {
203
- return function (candidate) {
284
+ return function (candidate ) {
204
285
  /* istanbul ignore if */
205
286
  if (typeof candidate !== 'string') {
206
- // Given the way nock is written, it seems like `candidate` will always
207
- // be a string, regardless of what options might be passed to it.
208
- // However the code used to contain a truthiness test of `candidate`.
209
- // The check is being preserved for now.
210
287
  throw Error(
211
288
  `Nock internal assertion failed: typeof candidate is ${typeof candidate}. If you encounter this error, please report it as a bug.`,
212
289
  )
@@ -219,7 +296,7 @@ class Scope extends EventEmitter {
219
296
  }
220
297
 
221
298
  filteringPath() {
222
- this.transformPathFunction = this.buildFilter.apply(this, arguments)
299
+ this.transformPathFunction = this.buildFilter.apply(this, arguments )
223
300
  if (!this.transformPathFunction) {
224
301
  throw new Error(
225
302
  'Invalid arguments: filtering path should be a function or a regular expression',
@@ -229,7 +306,10 @@ class Scope extends EventEmitter {
229
306
  }
230
307
 
231
308
  filteringRequestBody() {
232
- this.transformRequestBodyFunction = this.buildFilter.apply(this, arguments)
309
+ this.transformRequestBodyFunction = this.buildFilter.apply(
310
+ this,
311
+ arguments ,
312
+ )
233
313
  if (!this.transformRequestBodyFunction) {
234
314
  throw new Error(
235
315
  'Invalid arguments: filtering request body should be a function or a regular expression',
@@ -238,13 +318,13 @@ class Scope extends EventEmitter {
238
318
  return this
239
319
  }
240
320
 
241
- matchHeader(name, value) {
321
+ matchHeader(name , value ) {
242
322
  // We use lower-case header field names throughout Nock.
243
323
  this.matchHeaders.push({ name: name.toLowerCase(), value })
244
324
  return this
245
325
  }
246
326
 
247
- defaultReplyHeaders(headers) {
327
+ defaultReplyHeaders(headers ) {
248
328
  this._defaultReplyHeaders = common.headersInputToRawArray(headers)
249
329
  return this
250
330
  }
@@ -257,10 +337,6 @@ class Scope extends EventEmitter {
257
337
  return this
258
338
  }
259
339
 
260
- /**
261
- * @private
262
- * @returns {boolean}
263
- */
264
340
  shouldPersist() {
265
341
  return this._persist
266
342
  }
@@ -270,7 +346,7 @@ class Scope extends EventEmitter {
270
346
  return this
271
347
  }
272
348
 
273
- replyDate(d) {
349
+ replyDate(d ) {
274
350
  this.date = d || new Date()
275
351
  return this
276
352
  }
@@ -280,20 +356,20 @@ class Scope extends EventEmitter {
280
356
  }
281
357
  }
282
358
 
283
- function loadDefs(path) {
359
+ function loadDefs(path ) {
284
360
  if (!fs) {
285
361
  throw new Error('No fs')
286
362
  }
287
363
 
288
- const contents = fs.readFileSync(path)
364
+ const contents = fs.readFileSync(path)
289
365
  return JSON.parse(contents)
290
366
  }
291
367
 
292
- function load(path) {
368
+ function load(path ) {
293
369
  return define(loadDefs(path))
294
370
  }
295
371
 
296
- function getStatusFromDefinition(nockDef) {
372
+ function getStatusFromDefinition(nockDef ) {
297
373
  // Backward compatibility for when `status` was encoded as string in `reply`.
298
374
  if (nockDef.reply !== undefined) {
299
375
  const parsedReply = parseInt(nockDef.reply, 10)
@@ -308,11 +384,11 @@ function getStatusFromDefinition(nockDef) {
308
384
  return nockDef.status || DEFAULT_STATUS_OK
309
385
  }
310
386
 
311
- function getScopeFromDefinition(nockDef) {
387
+ function getScopeFromDefinition(nockDef ) {
312
388
  // Backward compatibility for when `port` was part of definition.
313
389
  if (nockDef.port !== undefined) {
314
390
  // Include `port` into scope if it doesn't exist.
315
- const url = URL.parse(nockDef.scope)
391
+ const url = URL.parse(nockDef.scope)
316
392
 
317
393
  if (url.port === '') {
318
394
  return `${nockDef.scope}:${nockDef.port}`
@@ -328,7 +404,7 @@ function getScopeFromDefinition(nockDef) {
328
404
  return nockDef.scope
329
405
  }
330
406
 
331
- function tryJsonParse(string) {
407
+ function tryJsonParse(string ) {
332
408
  try {
333
409
  return JSON.parse(string)
334
410
  } catch {
@@ -336,10 +412,10 @@ function tryJsonParse(string) {
336
412
  }
337
413
  }
338
414
 
339
- function define(nockDefs) {
340
- const scopes = []
415
+ function define(nockDefs ) {
416
+ const scopes = []
341
417
 
342
- nockDefs.forEach(function (nockDef) {
418
+ nockDefs.forEach(function (nockDef ) {
343
419
  const nscope = getScopeFromDefinition(nockDef)
344
420
  const npath = nockDef.path
345
421
  if (!nockDef.method) {
@@ -377,13 +453,13 @@ function define(nockDefs) {
377
453
 
378
454
  // If request headers were specified filter by them.
379
455
  Object.entries(reqheaders).forEach(([fieldName, value]) => {
380
- scope.matchHeader(fieldName, value)
456
+ scope.matchHeader(fieldName, value )
381
457
  })
382
458
 
383
459
  const acceptableFilters = ['filteringRequestBody', 'filteringPath']
384
460
  acceptableFilters.forEach(filter => {
385
461
  if (nockDef[filter]) {
386
- scope[filter](nockDef[filter])
462
+ ;(scope )[filter](nockDef[filter])
387
463
  }
388
464
  })
389
465
 
@@ -397,9 +473,4 @@ function define(nockDefs) {
397
473
  return scopes
398
474
  }
399
475
 
400
- module.exports = {
401
- Scope,
402
- load,
403
- loadDefs,
404
- define,
405
- }
476
+ export { Scope, load, loadDefs, define }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module stringify
3
+ * @private
4
+ * Safe JSON.stringify that handles circular references.
5
+ * @see https://github.com/moll/json-stringify-safe/blob/02cfafd45f06d076ac4bf0dd28be6738a07a72f9/stringify.js
6
+ * @license
7
+ * The ISC License
8
+ *
9
+ * Copyright (c) Isaac Z. Schlueter and Contributors
10
+ *
11
+ * Permission to use, copy, modify, and/or distribute this software for any
12
+ * purpose with or without fee is hereby granted, provided that the above
13
+ * copyright notice and this permission notice appear in all copies.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
+ */
23
+ declare function stringify(obj: any): string;
24
+ export default stringify;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @module stringify
3
+ * @private
4
+ * Safe JSON.stringify that handles circular references.
5
+ * @see https://github.com/moll/json-stringify-safe/blob/02cfafd45f06d076ac4bf0dd28be6738a07a72f9/stringify.js
6
+ * @license
7
+ * The ISC License
8
+ *
9
+ * Copyright (c) Isaac Z. Schlueter and Contributors
10
+ *
11
+ * Permission to use, copy, modify, and/or distribute this software for any
12
+ * purpose with or without fee is hereby granted, provided that the above
13
+ * copyright notice and this permission notice appear in all copies.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
+ */
23
+
24
+ function stringify(obj ) {
25
+ return JSON.stringify(obj, safeReplacer())
26
+ }
27
+
28
+ function cycleReplacer(stack , keys , value ) {
29
+ if (stack[0] === value) return '[Circular ~]'
30
+ return `[Circular ~.${keys.slice(0, stack.indexOf(value)).join('.')}]`
31
+ }
32
+
33
+ function safeReplacer(stack = [], keys = []) {
34
+ return function ( key , value ) {
35
+ if (stack.length > 0) {
36
+ const thisPos = stack.indexOf(this)
37
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
38
+ ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
39
+ if (~stack.indexOf(value)) {
40
+ value = cycleReplacer(stack, keys, value)
41
+ }
42
+ } else {
43
+ stack.push(value)
44
+ }
45
+
46
+ return value
47
+ }
48
+ }
49
+
50
+ export default stringify
@@ -0,0 +1,4 @@
1
+ import { Readable as ReadableStream } from 'node:stream';
2
+ declare function getGetRequestBody(request: Request): ReadableStream;
3
+ declare function setGetRequestBody(request: Request, body: ArrayBuffer): void;
4
+ export { getGetRequestBody, setGetRequestBody };
@@ -0,0 +1,16 @@
1
+ import { Readable as ReadableStream } from 'node:stream'
2
+
3
+ const kGetRequestBody = Symbol('kGetRequestBody')
4
+
5
+ function getGetRequestBody(request ) {
6
+ if (request.method !== 'GET') {
7
+ throw new Error('The request method must be GET')
8
+ }
9
+ return ReadableStream.from(Reflect.get(request, kGetRequestBody))
10
+ }
11
+
12
+ function setGetRequestBody(request , body ) {
13
+ Reflect.set(request, kGetRequestBody, Buffer.from(body))
14
+ }
15
+
16
+ export { getGetRequestBody, setGetRequestBody }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "15.0.0",
10
+ "version": "15.0.1",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -17,21 +17,26 @@
17
17
  "url": "https://github.com/nock/nock/issues"
18
18
  },
19
19
  "engines": {
20
- "node": ">=18.20.0 <20 || >=20.12.1"
20
+ "node": ">=20.12.1"
21
+ },
22
+ "main": "./dist/index.js",
23
+ "type": "module",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
21
30
  },
22
- "main": "./index.js",
23
- "types": "types",
24
31
  "dependencies": {
25
- "@mswjs/interceptors": "^0.39.5",
26
- "json-stringify-safe": "^5.0.1"
32
+ "@mswjs/interceptors": "^0.44.0"
27
33
  },
28
34
  "devDependencies": {
29
- "@definitelytyped/dtslint": "^0.0.163",
30
35
  "@eslint/js": "^9.27.0",
31
- "@jest/globals": "^29.7.0",
32
36
  "@sinonjs/fake-timers": "^11.2.2",
33
37
  "@types/node": "^22.15.3",
34
38
  "assert-rejects": "^1.0.0",
39
+ "c8": "^11.0.0",
35
40
  "chai": "^4.1.2",
36
41
  "dirty-chai": "^2.0.1",
37
42
  "eslint": "^9.27.0",
@@ -41,35 +46,33 @@
41
46
  "form-data": "^4.0.0",
42
47
  "globals": "^16.1.0",
43
48
  "got": "^11.8.6",
44
- "jest": "^29.7.0",
45
49
  "mocha": "^11.7.2",
46
50
  "npm-run-all": "^4.1.5",
47
- "nyc": "^15.0.0",
48
- "prettier": "3.2.5",
49
- "proxyquire": "^2.1.0",
51
+ "prettier": "3.6.2",
50
52
  "rimraf": "^3.0.0",
51
- "semantic-release": "^24.1.0",
53
+ "semantic-release": "^25.0.3",
52
54
  "sinon": "^17.0.1",
53
55
  "sinon-chai": "^3.7.0",
54
- "typescript": "^5.0.4",
56
+ "typescript": "^6.0.3",
57
+ "typescript-eslint": "^8.58.2",
55
58
  "undici": "^7.9.0"
56
59
  },
57
60
  "scripts": {
58
61
  "format:fix": "prettier --write '**/*.{js,json,md,ts,yml,yaml}'",
59
62
  "format": "prettier --check '**/*.{js,json,md,ts,yml,yaml}'",
60
63
  "lint": "run-p lint:js lint:ts",
61
- "lint:js": "eslint --cache --cache-location './.cache/eslint' '**/*.js'",
62
- "lint:js:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.js'",
63
- "lint:ts": "dtslint --expectOnly types",
64
- "test": "nyc --reporter=lcov --reporter=text mocha --recursive tests",
64
+ "lint:js": "eslint --cache --cache-location './.cache/eslint' '**/*.{js,ts}'",
65
+ "lint:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.{js,ts}'",
66
+ "lint:ts": "tsc --noEmit",
67
+ "build": "rimraf dist && node scripts/build.js && tsc -p tsconfig.build.json",
68
+ "test": "c8 --reporter=lcov --reporter=text mocha --recursive tests",
65
69
  "test:coverage": "open coverage/lcov-report/index.html",
66
- "test:jest": "jest tests_jest --detectLeaks"
70
+ "test:leak": "node --expose-gc scripts/test-leak.js",
71
+ "test:build": "npm run build && node scripts/test-build.js"
67
72
  },
68
73
  "license": "MIT",
69
74
  "files": [
70
- "index.js",
71
- "lib",
72
- "types/index.d.ts"
75
+ "dist"
73
76
  ],
74
77
  "release": {
75
78
  "branches": [