Browse Source

promisify _server.js

http2
Vsevolod Strukchinsky 9 years ago
parent
commit
e237ca142d
  1. 7
      test/_server.js
  2. 10
      test/arguments.js
  3. 9
      test/error.js
  4. 9
      test/gzip.js
  5. 9
      test/headers.js
  6. 9
      test/helpers.js
  7. 9
      test/http.js
  8. 9
      test/https.js
  9. 9
      test/json.js
  10. 9
      test/post.js
  11. 9
      test/redirects.js
  12. 9
      test/retry.js
  13. 9
      test/stream.js
  14. 9
      test/unix-socket.js

7
test/_server.js

@ -1,5 +1,6 @@
import http from 'http';
import https from 'https';
import pify from 'pify';
export const host = 'localhost';
export let port = 6767;
@ -15,6 +16,9 @@ export const createServer = port2 => {
s.url = `http://${host}:${port}`;
s.protocol = 'http';
s.listen = pify(s.listen);
s.close = pify(s.close);
return s;
};
@ -28,5 +32,8 @@ export const createSSLServer = (portSSL2, opts) => {
s.url = `https://${host}:${portSSL}`;
s.protocol = 'https';
s.listen = pify(s.listen);
s.close = pify(s.close);
return s;
};

10
test/arguments.js

@ -1,4 +1,5 @@
import test from 'ava';
import pify from 'pify';
import got from '../';
import {createServer} from './_server';
@ -17,8 +18,8 @@ s.on('/?test=wow', (req, res) => {
res.end(req.url);
});
test.before('arguments - setup', t => {
s.listen(s.port, () => t.end());
test.before('arguments - setup', async t => {
await s.listen(s.port);
});
test('arguments - url argument is required', async t => {
@ -47,7 +48,6 @@ test('arguments - should throw with auth in url', async t => {
}
});
test.after('arguments - cleanup', t => {
s.close();
t.end();
test.after('arguments - cleanup', async t => {
await s.close();
});

9
test/error.js

@ -9,8 +9,8 @@ s.on('/', (req, res) => {
res.end('not');
});
test.before('error - setup', t => {
s.listen(s.port, () => t.end());
test.before('error - setup', async t => {
await s.listen(s.port);
});
test('error - error message', async t => {
@ -53,7 +53,6 @@ test('error - options.body error message', async t => {
}
});
test.after('error - cleanup', t => {
s.close();
t.end();
test.after('error - cleanup', async t => {
await s.close();
});

9
test/gzip.js

@ -20,8 +20,8 @@ s.on('/corrupted', (req, res) => {
res.end('Not gzipped content');
});
test.before('gzip - setup', t => {
s.listen(s.port, () => t.end());
test.before('gzip - setup', async t => {
await s.listen(s.port);
});
test('gzip - ungzip content', async t => {
@ -43,7 +43,6 @@ test('gzip - preserve headers property', async t => {
t.ok((await got(s.url)).headers);
});
test.after('gzip - cleanup', t => {
s.close();
t.end();
test.after('gzip - cleanup', async t => {
await s.close();
});

9
test/headers.js

@ -8,8 +8,8 @@ s.on('/', (req, res) => {
res.end(JSON.stringify(req.headers));
});
test.before('headers - setup', t => {
s.listen(s.port, () => t.end());
test.before('headers - setup', async t => {
await s.listen(s.port);
});
test('headers - send user-agent header by default', async t => {
@ -37,7 +37,6 @@ test('headers - transform headers names to lowercase', async t => {
t.is(headers['user-agent'], 'test');
});
test.after('headers - cleanup', t => {
s.close();
t.end();
test.after('headers - cleanup', async t => {
await s.close();
});

9
test/helpers.js

@ -13,8 +13,8 @@ s.on('/404', (req, res) => {
res.end('not found');
});
test.before('helpers - setup', t => {
s.listen(s.port, () => t.end());
test.before('helpers - setup', async t => {
await s.listen(s.port);
});
test('helpers - callback mode', t => {
@ -43,7 +43,6 @@ test('helpers - promise mode', async t => {
}
});
test.after('helpers - cleanup', t => {
s.close();
t.end();
test.after('helpers - cleanup', async t => {
await s.close();
});

9
test/http.js

@ -23,8 +23,8 @@ s.on('/?recent=true', (req, res) => {
res.end('recent');
});
test.before('http - setup', t => {
s.listen(s.port, () => t.end());
test.before('http - setup', async t => {
await s.listen(s.port);
});
test('http - simple request', async t => {
@ -68,7 +68,6 @@ test('http - query option', async t => {
t.is((await got(s.url, {query: 'recent=true'})).body, 'recent');
});
test.after('http - cleanup', t => {
s.close();
t.end();
test.after('http - cleanup', async t => {
await s.close();
});

9
test/https.js

@ -37,10 +37,10 @@ test.before('https - create pem', async t => {
cert = keys.certificate;
});
test.before('https - setup', t => {
test.before('https - setup', async t => {
s = createSSLServer(portSSL + 1, {key, cert});
s.on('/', (req, res) => res.end('ok'));
s.listen(s.port, () => t.end());
await s.listen(s.port);
});
test('https - redirects from http to https works', async t => {
@ -60,7 +60,6 @@ test('https - make request to https server with ca', async t => {
t.is(body, 'ok');
});
test.after('https - cleanup', t => {
s.close();
t.end();
test.after('https - cleanup', async t => {
await s.close();
});

9
test/json.js

@ -27,8 +27,8 @@ s.on('/non200-invalid', (req, res) => {
res.end('Internal error');
});
test.before('json - setup', t => {
s.listen(s.port, () => t.end());
test.before('json - setup', async t => {
await s.listen(s.port);
});
test('json - json option should parse response', async t => {
@ -71,7 +71,6 @@ test('json - json option should catch errors on invalid non-200 responses', asyn
}
});
test.after('json - cleanup', t => {
s.close();
t.end();
test.after('json - cleanup', async t => {
await s.close();
});

9
test/post.js

@ -20,8 +20,8 @@ s.on('/empty', (req, res) => {
res.end();
});
test.before('post - setup', t => {
s.listen(s.port, () => t.end());
test.before('post - setup', async t => {
await s.listen(s.port);
});
test('post - GET can have body', async t => {
@ -109,7 +109,6 @@ test('post - works with plain object in body', async t => {
t.is(body['content-type'], 'doge');
});
test.after('post - cleanup', t => {
s.close();
t.end();
test.after('post - cleanup', async t => {
await s.close();
});

9
test/redirects.js

@ -36,8 +36,8 @@ s.on('/relativeQuery?bang', (req, res) => {
res.end();
});
test.before('redirects - setup', t => {
s.listen(s.port, () => t.end());
test.before('redirects - setup', async t => {
await s.listen(s.port);
});
test('redirects - follows redirect', async t => {
@ -76,7 +76,6 @@ test('redirects - redirect only GET and HEAD requests', async t => {
}
});
test.after('redirects - cleanup', t => {
s.close();
t.end();
test.after('redirects - cleanup', async t => {
await s.close();
});

9
test/retry.js

@ -18,8 +18,8 @@ s.on('/try-me', () => {
trys++;
});
test.before('retry - setup', t => {
s.listen(s.port, () => t.end());
test.before('retry - setup', async t => {
await s.listen(s.port);
});
test('retry - timeout errors', async t => {
@ -35,7 +35,6 @@ test('retry - can be disabled with option', async t => {
t.is(trys, 1);
});
test.after('error - cleanup', t => {
s.close();
t.end();
test.after('error - cleanup', async t => {
await s.close();
});

9
test/stream.js

@ -24,8 +24,8 @@ s.on('/error', (req, res) => {
res.end();
});
test.before('stream - setup', t => {
s.listen(s.port, () => t.end());
test.before('stream - setup', async t => {
await s.listen(s.port);
});
test('stream - json option can not be used in stream mode', t => {
@ -121,7 +121,6 @@ test('stream - error event', t => {
});
});
test.after('stream - cleanup', t => {
s.close();
t.end();
test.after('stream - cleanup', async t => {
await s.close();
});

9
test/unix-socket.js

@ -11,8 +11,8 @@ s.on('/', (req, res) => {
res.end('ok');
});
test.before('unix-socket - setup', t => {
s.listen(socketPath, () => t.end());
test.before('unix-socket - setup', async t => {
await s.listen(socketPath);
});
test('unix-socket - request via unix socket', async t => {
@ -25,7 +25,6 @@ test('unix-socket - protocol-less request', async t => {
t.is((await got(url)).body, 'ok');
});
test.after('unix-socket - cleanup', t => {
s.close();
t.end();
test.after('unix-socket - cleanup', async t => {
await s.close();
});

Loading…
Cancel
Save