nock 13.5.4 → 13.5.6

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/common.js CHANGED
@@ -593,31 +593,35 @@ function deepEqual(expected, actual) {
593
593
  return expected === actual
594
594
  }
595
595
 
596
- const timeouts = []
597
- const intervals = []
598
- const immediates = []
596
+ const timeouts = new Set()
597
+ const immediates = new Set()
599
598
 
600
599
  const wrapTimer =
601
600
  (timer, ids) =>
602
- (...args) => {
603
- const id = timer(...args)
604
- ids.push(id)
601
+ (callback, ...timerArgs) => {
602
+ const cb = (...callbackArgs) => {
603
+ try {
604
+ // eslint-disable-next-line n/no-callback-literal
605
+ callback(...callbackArgs)
606
+ } finally {
607
+ ids.delete(id)
608
+ }
609
+ }
610
+ const id = timer(cb, ...timerArgs)
611
+ ids.add(id)
605
612
  return id
606
613
  }
607
614
 
608
615
  const setTimeout = wrapTimer(timers.setTimeout, timeouts)
609
- const setInterval = wrapTimer(timers.setInterval, intervals)
610
616
  const setImmediate = wrapTimer(timers.setImmediate, immediates)
611
617
 
612
618
  function clearTimer(clear, ids) {
613
- while (ids.length) {
614
- clear(ids.shift())
615
- }
619
+ ids.forEach(clear)
620
+ ids.clear()
616
621
  }
617
622
 
618
623
  function removeAllTimers() {
619
624
  clearTimer(clearTimeout, timeouts)
620
- clearTimer(clearInterval, intervals)
621
625
  clearTimer(clearImmediate, immediates)
622
626
  }
623
627
 
@@ -762,7 +766,6 @@ module.exports = {
762
766
  removeAllTimers,
763
767
  restoreOverriddenRequests,
764
768
  setImmediate,
765
- setInterval,
766
769
  setTimeout,
767
770
  stringifyRequest,
768
771
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "13.5.4",
10
+ "version": "13.5.6",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -45,10 +45,10 @@
45
45
  "mocha": "^9.1.3",
46
46
  "npm-run-all": "^4.1.5",
47
47
  "nyc": "^15.0.0",
48
- "prettier": "3.2.4",
48
+ "prettier": "3.2.5",
49
49
  "proxyquire": "^2.1.0",
50
50
  "rimraf": "^3.0.0",
51
- "semantic-release": "^22.0.5",
51
+ "semantic-release": "^24.1.0",
52
52
  "sinon": "^15.0.1",
53
53
  "sinon-chai": "^3.7.0",
54
54
  "typescript": "^5.0.4"
package/types/index.d.ts CHANGED
@@ -289,7 +289,7 @@ declare namespace nock {
289
289
  interface BackOptions {
290
290
  before?: (def: Definition) => void
291
291
  after?: (scope: Scope) => void
292
- afterRecord?: (defs: Definition[]) => Definition[]
292
+ afterRecord?: (defs: Definition[]) => Definition[] | string
293
293
  recorder?: RecorderOptions
294
294
  }
295
295
  }