koa-lite/test/helpers/context.js
TJ Holowaychuk c06d30286f Merge pull request #527 from tejasmanohar/module_exports
no more exports! only module.exports
2015-10-12 23:46:56 -07:00

23 lines
780 B
JavaScript

'use strict';
const Stream = require('stream');
const Koa = require('../..');
module.exports = function(req, res){
const socket = new Stream.Duplex();
req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype };
res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype };
res.getHeader = function(k){ return res._headers[k.toLowerCase()] };
res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v };
res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()] };
return (new Koa()).createContext(req, res);
}
module.exports.request = function(req, res){
return module.exports(req, res).request;
}
module.exports.response = function(req, res){
return module.exports(req, res).response;
}