nock 13.5.3 → 13.5.5
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 +15 -12
- package/lib/interceptor.js +9 -12
- package/package.json +3 -3
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
|
|
598
|
-
const immediates = []
|
|
596
|
+
const timeouts = new Set()
|
|
597
|
+
const immediates = new Set()
|
|
599
598
|
|
|
600
599
|
const wrapTimer =
|
|
601
600
|
(timer, ids) =>
|
|
602
|
-
(...
|
|
603
|
-
const
|
|
604
|
-
|
|
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
|
-
|
|
614
|
-
|
|
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/lib/interceptor.js
CHANGED
|
@@ -198,10 +198,16 @@ module.exports = class Interceptor {
|
|
|
198
198
|
if (!fs) {
|
|
199
199
|
throw new Error('No fs')
|
|
200
200
|
}
|
|
201
|
-
const readStream = fs.createReadStream(filePath)
|
|
202
|
-
readStream.pause()
|
|
203
201
|
this.filePath = filePath
|
|
204
|
-
return this.reply(
|
|
202
|
+
return this.reply(
|
|
203
|
+
statusCode,
|
|
204
|
+
() => {
|
|
205
|
+
const readStream = fs.createReadStream(filePath)
|
|
206
|
+
readStream.pause()
|
|
207
|
+
return readStream
|
|
208
|
+
},
|
|
209
|
+
headers,
|
|
210
|
+
)
|
|
205
211
|
}
|
|
206
212
|
|
|
207
213
|
// Also match request headers
|
|
@@ -453,15 +459,6 @@ module.exports = class Interceptor {
|
|
|
453
459
|
markConsumed() {
|
|
454
460
|
this.interceptionCounter++
|
|
455
461
|
|
|
456
|
-
if (
|
|
457
|
-
(this.scope.shouldPersist() || this.counter > 0) &&
|
|
458
|
-
this.interceptionCounter > 1 &&
|
|
459
|
-
this.filePath
|
|
460
|
-
) {
|
|
461
|
-
this.body = fs.createReadStream(this.filePath)
|
|
462
|
-
this.body.pause()
|
|
463
|
-
}
|
|
464
|
-
|
|
465
462
|
remove(this)
|
|
466
463
|
|
|
467
464
|
if (!this.scope.shouldPersist() && this.counter < 1) {
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.5.
|
|
10
|
+
"version": "13.5.5",
|
|
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.
|
|
48
|
+
"prettier": "3.2.5",
|
|
49
49
|
"proxyquire": "^2.1.0",
|
|
50
50
|
"rimraf": "^3.0.0",
|
|
51
|
-
"semantic-release": "^
|
|
51
|
+
"semantic-release": "^23.0.2",
|
|
52
52
|
"sinon": "^15.0.1",
|
|
53
53
|
"sinon-chai": "^3.7.0",
|
|
54
54
|
"typescript": "^5.0.4"
|