Skip to content

Instantly share code, notes, and snippets.

@miensol
Created March 18, 2016 13:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save miensol/cb9bb5856363084fa84e to your computer and use it in GitHub Desktop.
Fake Express.js Request and Response
module.exports.request = () => {
class IncomingMessage extends require('http').IncomingMessage {
}
const request = new IncomingMessage();
request.__proto__ = require('express')().request;
return request;
};
module.exports.response = (request) => {
class ServerResponse extends require('http').ServerResponse {
}
request = request || module.exports.request();
const res = new ServerResponse(request);
res.__proto__ = require('express')().response;
res.req = request;
request.res = res;
return res;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment