koa-lite/test/helpers/context.js
Slobodan Stojanovic cc1d41f5e3 Refactor tests - add arrow functions
Refactor tests - move .should to the same line as arrow function
2015-10-25 13:26:36 -07:00

19 lines
714 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 = k => res._headers[k.toLowerCase()];
res.setHeader = (k, v) => res._headers[k.toLowerCase()] = v;
res.removeHeader = (k, v) => delete res._headers[k.toLowerCase()];
return (new Koa()).createContext(req, res);
};
module.exports.request = (req, res) => module.exports(req, res).request;
module.exports.response = (req, res) => module.exports(req, res).response;