How to use the @pollyjs/utils.HTTP_METHODS.forEach function in @pollyjs/utils

To help you get started, we’ve selected a few @pollyjs/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Netflix / pollyjs / packages / @pollyjs / adapter-node-http / src / index.js View on Github external
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.