Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setupNock() {
const adapter = this;
// Make sure there aren't any other interceptors defined
nock.cleanAll();
// Create our interceptor that will match all hosts
const interceptor = nock(/.*/).persist();
HTTP_METHODS.forEach(m => {
// Add an intercept for each supported HTTP method that will match all paths
interceptor.intercept(/.*/, m).reply(function(_, body, respond) {
const { req, method } = this;
const { headers } = req;
const parsedArguments = normalizeClientRequestArgs(
...REQUEST_ARGUMENTS.get(req)
);
const url = getUrlFromOptions(parsedArguments.options);
if (body) {
if (
typeof body === 'string' &&
!isUtf8Representable(Buffer.from(body, 'hex'))
) {
// Nock internally converts a binary buffer into its hexadecimal
// representation so convert it back to a buffer.