saveRecording(recording, data) { fs.outputJsonSync(this.filenameFor(recording), data, { spaces: 2 }); return this.respond(201); }
/** * @param {PollyRequest} pollyRequest * @param {Object} normalizedResponse The normalized response generated from the recording entry * @param {Object} recordingEntry The entire recording entry */ async onReplay(pollyRequest, normalizedResponse) { await pollyRequest.respond(normalizedResponse); }
/** * @param {PollyRequest} pollyRequest */ async onPassthrough(pollyRequest) { const response = await this.passthroughRequest(pollyRequest); await pollyRequest.respond(response); }
deleteRecording(recording) { const recordingFilename = this.filenameFor(recording); if (fs.existsSync(recordingFilename)) { fs.removeSync(recordingFilename); } return this.respond(200); }
async respondToRequest(pollyRequest, error) { const { request } = pollyRequest.requestArguments; const { response } = pollyRequest; if (error) { // If an error was returned then we force puppeteer to abort the current // request. This will emit the `requestfailed` page event and allow the end // user to handle the error. await request.abort(); } else { await request.respond({ status: response.statusCode, headers: response.headers, body: response.body }); } }
xhr.respond(statusCode, headers, responseBody);
saveRecording(recording, data) { fs.outputJsonSync(this.filenameFor(recording), data, { spaces: 2 }); return this.respond(201); }
/** * @param {PollyRequest} pollyRequest * @param {PollyResponse} pollyResponse */ async onIntercept(pollyRequest, pollyResponse) { await pollyRequest.respond(pollyResponse); }
/** * @param {PollyRequest} pollyRequest * @param {PollyResponse} pollyResponse */ async onIntercept(pollyRequest, pollyResponse) { await pollyRequest.respond(pollyResponse); }
/** * @param {PollyRequest} pollyRequest * @param {Object} normalizedResponse The normalized response generated from the recording entry * @param {Object} recordingEntry The entire recording entry */ async onReplay(pollyRequest, normalizedResponse) { await pollyRequest.respond(normalizedResponse); }
deleteRecording(recording) { const recordingFilename = this.filenameFor(recording); if (fs.existsSync(recordingFilename)) { fs.removeSync(recordingFilename); } return this.respond(200); }
/** * @param {PollyRequest} pollyRequest */ async onPassthrough(pollyRequest) { const response = await this.passthroughRequest(pollyRequest); await pollyRequest.respond(response); }
async respondToRequest(pollyRequest, error) { const { request } = pollyRequest.requestArguments; const { response } = pollyRequest; if (error) { // If an error was returned then we force puppeteer to abort the current // request. This will emit the `requestfailed` page event and allow the end // user to handle the error. await request.abort(); } else { await request.respond({ status: response.statusCode, headers: response.headers, body: response.body }); } }