Skip to content

Commit

Permalink
Remove duplicated code "getUrl" (tests) (#436)
Browse files Browse the repository at this point in the history
Co-authored-by: Joey <jrogues@hubside.com>
  • Loading branch information
joeyrogues and Joey committed May 16, 2020
1 parent 59bbb73 commit c85f41d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
3 changes: 3 additions & 0 deletions test/_test-utils.js
@@ -0,0 +1,3 @@
module.exports = ({http, micro, listen}) => ({
getUrl: fn => listen(new http.Server(micro(fn)))
});
6 changes: 1 addition & 5 deletions test/development.js
Expand Up @@ -7,11 +7,7 @@ const http = require('http');
process.env.NODE_ENV = 'development';
const micro = require('../packages/micro/lib');

const getUrl = fn => {
const srv = new http.Server(micro(fn));

return listen(srv);
};
const {getUrl} = require('./_test-utils')({http, micro, listen});

test('send(200, <Object>) is pretty-printed', async t => {
const fn = () => ({woot: 'yes'});
Expand Down
7 changes: 1 addition & 6 deletions test/index.js
Expand Up @@ -6,15 +6,10 @@ const sleep = require('then-sleep');
const resumer = require('resumer');
const listen = require('test-listen');
const micro = require('../packages/micro/lib');
const {getUrl} = require('./_test-utils')({http, micro, listen});

const {send, sendError, buffer, json} = micro;

const getUrl = fn => {
const srv = new http.Server(micro(fn));

return listen(srv);
};

test('send(200, <String>)', async t => {
const fn = async (req, res) => {
send(res, 200, 'woot');
Expand Down
6 changes: 1 addition & 5 deletions test/production.js
Expand Up @@ -7,11 +7,7 @@ const listen = require('test-listen');
process.env.NODE_ENV = 'production';
const micro = require('../packages/micro');

const getUrl = fn => {
const srv = new http.Server(micro(fn));

return listen(srv);
};
const {getUrl} = require('./_test-utils')({http, micro, listen});

test.serial('errors are printed in console in production', async t => {
let logged = false;
Expand Down

0 comments on commit c85f41d

Please sign in to comment.