Browse Source

fix lint issues with latest XO

node-7
Sindre Sorhus 9 years ago
parent
commit
9bb4696c16
  1. 12
      index.js
  2. 6
      test/arguments.js
  3. 4
      test/error.js
  4. 22
      test/headers.js
  5. 1
      test/helpers/server.js
  6. 5
      test/http.js
  7. 7
      test/https.js
  8. 15
      test/post.js
  9. 12
      test/redirects.js
  10. 26
      test/retry.js

12
index.js

@ -198,7 +198,11 @@ function normalizeArguments(url, opts) {
}
opts = Object.assign(
{protocol: 'http:', path: '', retries: 5},
{
protocol: 'http:',
path: '',
retries: 5
},
url,
opts
);
@ -265,7 +269,7 @@ function normalizeArguments(url, opts) {
const noise = Math.random() * 100;
return (1 << iter) * 1000 + noise;
return ((1 << iter) * 1000) + noise;
};
}
@ -279,8 +283,8 @@ function normalizeArguments(url, opts) {
function got(url, opts) {
try {
return asPromise(normalizeArguments(url, opts));
} catch (error) {
return Promise.reject(error);
} catch (err) {
return Promise.reject(err);
}
}

6
test/arguments.js

@ -37,7 +37,11 @@ test('options are optional', async t => {
});
test('accepts url.parse object as first argument', async t => {
t.is((await got({hostname: s.host, port: s.port, path: '/test'})).body, '/test');
t.is((await got({
hostname: s.host,
port: s.port,
path: '/test'
})).body, '/test');
});
test('overrides querystring from opts', async t => {

4
test/error.js

@ -22,8 +22,8 @@ test('properties', async t => {
} catch (err) {
t.truthy(err);
t.truthy(err.response);
t.false(err.propertyIsEnumerable('response'));
t.false(err.hasOwnProperty('code'));
t.false({}.propertyIsEnumerable.call(err, 'response'));
t.false({}.hasOwnProperty.call(err, 'code'));
t.is(err.message, 'Response code 404 (Not Found)');
t.is(err.host, `${s.host}:${s.port}`);
t.is(err.method, 'GET');

22
test/headers.js

@ -30,7 +30,12 @@ test('accept header with json option', async t => {
let headers = (await got(s.url, {json: true})).body;
t.is(headers.accept, 'application/json');
headers = (await got(s.url, {headers: {accept: ''}, json: true})).body;
headers = (await got(s.url, {
headers: {
accept: ''
},
json: true
})).body;
t.is(headers.accept, '');
});
@ -40,12 +45,23 @@ test('host', async t => {
});
test('transform names to lowercase', async t => {
const headers = (await got(s.url, {headers: {'USER-AGENT': 'test'}, json: true})).body;
const headers = (await got(s.url, {
headers: {
'USER-AGENT': 'test'
},
json: true
})).body;
t.is(headers['user-agent'], 'test');
});
test('zero content-length', async t => {
const headers = (await got(s.url, {headers: {'content-length': 0}, body: 'sup', json: true})).body;
const headers = (await got(s.url, {
headers: {
'content-length': 0
},
body: 'sup',
json: true
})).body;
t.is(headers['content-length'], '0');
});

1
test/helpers/server.js

@ -3,6 +3,7 @@ const http = require('http');
const https = require('https');
const pify = require('pify');
const getPort = require('get-port');
const host = exports.host = 'localhost';
exports.createServer = function () {

5
test/http.js

@ -58,7 +58,10 @@ test('buffer on encoding === null', async t => {
test('timeout option', async t => {
try {
await got(`${s.url}/404`, {timeout: 1, retries: 0});
await got(`${s.url}/404`, {
timeout: 1,
retries: 0
});
t.fail('Exception was not thrown');
} catch (err) {
t.is(err.code, 'ETIMEDOUT');

7
test/https.js

@ -10,7 +10,10 @@ let caRootCert;
const pemP = pify(pem, Promise);
test.before('setup', async () => {
const caKeys = await pemP.createCertificate({days: 1, selfSigned: true});
const caKeys = await pemP.createCertificate({
days: 1,
selfSigned: true
});
const caRootKey = caKeys.serviceKey;
caRootCert = caKeys.certificate;
@ -31,7 +34,7 @@ test.before('setup', async () => {
const key = keys.clientKey;
const cert = keys.certificate;
s = await createSSLServer({key, cert});
s = await createSSLServer({key, cert}); // eslint-disable-line object-property-newline
s.on('/', (req, res) => res.end('ok'));

15
test/post.js

@ -51,17 +51,26 @@ test('works with empty post response', async t => {
});
test('content-length header with string body', async t => {
const {body} = await got(`${s.url}/headers`, {body: 'wow', json: true});
const {body} = await got(`${s.url}/headers`, {
body: 'wow',
json: true
});
t.is(body['content-length'], '3');
});
test('content-length header with Buffer body', async t => {
const {body} = await got(`${s.url}/headers`, {body: new Buffer('wow'), json: true});
const {body} = await got(`${s.url}/headers`, {
body: new Buffer('wow'),
json: true
});
t.is(body['content-length'], '3');
});
test('content-length header with Stream body', async t => {
const {body} = await got(`${s.url}/headers`, {body: intoStream(['wow']), json: true});
const {body} = await got(`${s.url}/headers`, {
body: intoStream(['wow']),
json: true
});
t.is(body['content-length'], undefined);
});

12
test/redirects.js

@ -10,7 +10,10 @@ let https;
const pemP = pify(pem, Promise);
test.before('setup', async () => {
const caKeys = await pemP.createCertificate({days: 1, selfSigned: true});
const caKeys = await pemP.createCertificate({
days: 1,
selfSigned: true
});
const caRootKey = caKeys.serviceKey;
const caRootCert = caKeys.certificate;
@ -31,7 +34,7 @@ test.before('setup', async () => {
const key = keys.clientKey;
const cert = keys.certificate;
https = await createSSLServer({key, cert});
https = await createSSLServer({key, cert}); // eslint-disable-line object-property-newline
https.on('/', (req, res) => {
res.end('https');
@ -108,7 +111,10 @@ test('query in options are not breaking redirects', async t => {
});
test('hostname+path in options are not breaking redirects', async t => {
t.is((await got(`${http.url}/relative`, {hostname: http.host, path: '/relative'})).body, 'reached');
t.is((await got(`${http.url}/relative`, {
hostname: http.host,
path: '/relative'
})).body, 'reached');
});
test('redirect only GET and HEAD requests', async t => {

26
test/retry.js

@ -37,7 +37,10 @@ test('works on timeout error', async t => {
test('can be disabled with option', async t => {
try {
await got(`${s.url}/try-me`, {timeout: 500, retries: 0});
await got(`${s.url}/try-me`, {
timeout: 500,
retries: 0
});
t.fail();
} catch (err) {
t.truthy(err);
@ -46,13 +49,19 @@ test('can be disabled with option', async t => {
});
test('function gets iter count', async t => {
await got(`${s.url}/fifth`, {timeout: 100, retries: iter => iter < 10});
await got(`${s.url}/fifth`, {
timeout: 100,
retries: iter => iter < 10
});
t.is(fifth, 6);
});
test('falsy value prevents retries', async t => {
try {
await got(`${s.url}/long`, {timeout: 100, retries: () => 0});
await got(`${s.url}/long`, {
timeout: 100,
retries: () => 0
});
} catch (err) {
t.truthy(err);
}
@ -60,10 +69,13 @@ test('falsy value prevents retries', async t => {
test('falsy value prevents retries #2', async t => {
try {
await got(`${s.url}/long`, {timeout: 100, retries: (iter, err) => {
t.truthy(err);
return false;
}});
await got(`${s.url}/long`, {
timeout: 100,
retries: (iter, err) => {
t.truthy(err);
return false;
}
});
} catch (err) {
t.truthy(err);
}

Loading…
Cancel
Save