Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated code "getUrl" (tests) #436

Merged
merged 1 commit into from May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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