constructor({ runId = 42 } = {}) {
    this.#cert = fakeCert()
    this.#runId = runId
    this.#server = https.createServer({
      key: this.#cert.privateKey,
      cert: this.#cert.certificate
    })
    this.#server.on('request', (req, res) => {
      const qs = querystring.decode(req.url.slice(req.url.indexOf('?') + 1))
      const handler = this.#handlers.get(qs.method)
      if (typeof handler !== 'function') {
        res.writeHead(500)
        return res.end('handler not found: ' + req.url)
      }

      /**
       * Send the response as serialized JSON.
       *
       * @param {object} params
       * @param {object} params.payload The object to serialize into a response.
       * @param {number} [params.code] The status code to use for the
       * response.
       * @memberof CollectorOutgoingResponse
       */
      res.json = function ({ payload, code = 200 }) {
        this.writeHead(code, { 'content-type': 'application/json' })
        this.end(JSON.stringify(payload))
      }

      /**
       * The query string associated with the request, parsed into an object.
       * @type {object}
       * @memberof CollectorIncomingRequest
       */
      req.query = qs

      /**
       * Retrieve the body of a POST-like request.
       *
       * @memberof CollectorIncomingRequest
       * @returns {Promise<string>} The body of an incoming POST-like request
       * collected as a string.
       */
      req.body = function () {
        let resolve
        let reject
        const promise = new Promise((_resolve, _reject) => {
          resolve = _resolve
          reject = _reject
        })

        let data = ''
        this.on('data', (d) => {
          data += d
        })
        this.on('end', () => {
          resolve(data)
        })
        this.on('error', (error) => {
          reject(error)
        })
        return promise
      }

      /**
       * Get the value of a specific header.
       *
       * @memberof CollectorIncomingRequest
       * @param {string} name
       * @returns {*}
       */
      req.getHeader = function (name) {
        return req.headers[name.toLowerCase()]
      }

      handler.isDone = true
      handler(req, res)
    })

    // We don't need this server keeping the process alive.
    this.#server.unref()
  }
Emulates the New Relic collector. Provides convenience methods that make
writing tests against collector processing easier.