How to use the @hapi/shot/lib/request.prototype function in @hapi/shot

To help you get started, we’ve selected a few @hapi/shot 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 strongloop / loopback-next / packages / testlab / src / shot.ts View on Github external
export function stubServerRequest(
  options: ShotRequestOptions,
): IncomingMessage {
  const stub = new ShotRequest(options);
  // Hacky workaround for Express, see
  // https://github.com/expressjs/express/blob/4.16.3/lib/middleware/init.js
  // https://github.com/hapijs/shot/issues/82#issuecomment-247943773
  // https://github.com/jfhbrook/pickleback
  Object.assign(stub, ShotRequest.prototype);
  return stub;
}
github cjihrig / artificial / lib / index.js View on Github external
function inject (dispatchFunc, options, callback) {
  options = (typeof options === 'string' ? { url: options } : options);
  Assert(typeof dispatchFunc === 'function', 'Invalid dispatch function');
  Joi.assert(options, schema);

  const req = new Request(options);
  const res = new Response(req, callback);

  // Bind the req and res methods, as Express sets the prototype internally.
  req._read = Request.prototype._read.bind(req);
  req.destroy = Request.prototype.destroy.bind(req);
  res.writeHead = Response.prototype.writeHead.bind(res);
  res.write = Response.prototype.write.bind(res);
  res.end = Response.prototype.end.bind(res);
  res.destroy = Response.prototype.destroy.bind(res);
  res.addTrailers = Response.prototype.addTrailers.bind(res);

  return req.prepare(() => { dispatchFunc(req, res); });
}
github cjihrig / artificial / lib / index.js View on Github external
function inject (dispatchFunc, options, callback) {
  options = (typeof options === 'string' ? { url: options } : options);
  Assert(typeof dispatchFunc === 'function', 'Invalid dispatch function');
  Joi.assert(options, schema);

  const req = new Request(options);
  const res = new Response(req, callback);

  // Bind the req and res methods, as Express sets the prototype internally.
  req._read = Request.prototype._read.bind(req);
  req.destroy = Request.prototype.destroy.bind(req);
  res.writeHead = Response.prototype.writeHead.bind(res);
  res.write = Response.prototype.write.bind(res);
  res.end = Response.prototype.end.bind(res);
  res.destroy = Response.prototype.destroy.bind(res);
  res.addTrailers = Response.prototype.addTrailers.bind(res);

  return req.prepare(() => { dispatchFunc(req, res); });
}

@hapi/shot

Injects a fake HTTP request/response into a node HTTP server

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis