koa-lite/test/helpers/context.js
broucz 4b1a1da652 test: switch all functions to arrow functions
closes #553

Update test: application -> use() should throw if not a function

Fix lint

Use arrow function

Refactor test using arrow function

Remove non mandatory brackets

fix for merge

Fix: missing refactor after merge

Use arrow function for old generator
2015-11-02 11:22:05 -08:00

19 lines
710 B
JavaScript

'use strict';
const Stream = require('stream');
const Koa = require('../..');
module.exports = (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;