@stephen-shopopop/tbx
    Preparing search index...

    Class Smoker

    Smoker is a mock server for testing HTTP requests and responses. It allows you to record requests, mock responses, and retrieve request history.

    Index

    Constructors

    Methods

    • Add mock request This method allows you to define a mock request with a specific HTTP method and path, along with an optional response object.

      Parameters

      • mock: Mock

        Mock object containing request and optional response

        • request.method

          HTTP method (GET, POST, etc.)

        • request.path

          Request path to match

        • response

          Optional response object containing status, headers, and body

        • response.status

          HTTP status code for the response

        • response.headers

          Optional headers for the response

        • response.body

          Optional body content for the response

      Returns string

    • Clear history of requests This method clears the recorded history of requests made to the mock server. It removes all entries from the history array and resets the recorder. After calling this method, the history will be empty, and all recorded requests will be discarded.

      Returns void

    • Destroy smoker server This method stops the smoker server and clears its history.

      Returns Promise<void>

    • Get address information of the smoker server This method retrieves the address information of the smoker server, including the port and address. It returns an AddressInfo object if the server is running, or undefined if the server is not started.

      Returns undefined | AddressInfo

      AddressInfo | undefined

    • Get history from mock requests This method retrieves the history of requests made to the mock server. It returns an array of history entries, each containing the mock ID, request details, and optional response data.

      Parameters

      • Optionalmock_id: string

        Optional mock ID to filter history If provided, only history entries matching the mock_id will be returned. If not provided, all history entries will be returned.

      Returns History[]

      Array of history entries

    • Get all records from all requests This method retrieves all recorded requests made to the mock server. Each record contains the request details, including the identifier, method, path, and any additional context information.

      Returns {
          id: string;
          request: Omit<Context, "body"> & { body: unknown; datetime: number };
      }[]

      Array of records

    • Start smoker server This method initializes the smoker server, allowing it to listen for incoming HTTP requests. It sets up the server to handle requests using the provided fetch callback.

      Returns Promise<Smoker>