Skip to content

Commit fd1dcad

Browse files
committed
make _replaySnapshot sync
1 parent 7beea36 commit fd1dcad

1 file changed

Lines changed: 27 additions & 33 deletions

File tree

lib/mock/snapshot-agent.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -182,39 +182,33 @@ class SnapshotAgent extends MockAgent {
182182
* Replays a recorded response
183183
*/
184184
_replaySnapshot (snapshot, handler) {
185-
return new Promise((resolve) => {
186-
// Simulate the response
187-
setImmediate(() => {
188-
try {
189-
const { response } = snapshot
190-
191-
const controller = {
192-
pause () {},
193-
resume () {},
194-
abort (reason) {
195-
this.aborted = true
196-
this.reason = reason
197-
},
198-
199-
aborted: false,
200-
paused: false
201-
}
202-
203-
handler.onRequestStart(controller)
204-
205-
handler.onResponseStart(controller, response.statusCode, response.headers)
206-
207-
// Body is always stored as base64 string
208-
const body = Buffer.from(response.body, 'base64')
209-
handler.onResponseData(controller, body)
210-
211-
handler.onResponseEnd(controller, response.trailers)
212-
resolve()
213-
} catch (error) {
214-
handler.onError?.(error)
215-
}
216-
})
217-
})
185+
try {
186+
const { response } = snapshot
187+
188+
const controller = {
189+
pause () { },
190+
resume () { },
191+
abort (reason) {
192+
this.aborted = true
193+
this.reason = reason
194+
},
195+
196+
aborted: false,
197+
paused: false
198+
}
199+
200+
handler.onRequestStart(controller)
201+
202+
handler.onResponseStart(controller, response.statusCode, response.headers)
203+
204+
// Body is always stored as base64 string
205+
const body = Buffer.from(response.body, 'base64')
206+
handler.onResponseData(controller, body)
207+
208+
handler.onResponseEnd(controller, response.trailers)
209+
} catch (error) {
210+
handler.onError?.(error)
211+
}
218212
}
219213

220214
/**

0 commit comments

Comments
 (0)