Skip to content

Commit 5c3adba

Browse files
szmarczaksindresorhus
authored andcommittedAug 3, 2018
Increase coverage (#543)
1 parent 10d22b7 commit 5c3adba

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed
 

‎source/normalize-arguments.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2+
/* istanbul ignore next: compatibility reason */
23
const URLGlobal = typeof URL === 'undefined' ? require('url').URL : URL; // TODO: Use the `URL` global when targeting Node.js 10
4+
/* istanbul ignore next: compatibility reason */
35
const URLSearchParamsGlobal = typeof URLSearchParams === 'undefined' ? require('url').URLSearchParams : URLSearchParams;
46
const is = require('@sindresorhus/is');
57
const toReadableStream = require('to-readable-stream');

‎source/progress.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ module.exports = {
2828
request.once('socket', socket => {
2929
const onSocketConnect = () => {
3030
progressInterval = setInterval(() => {
31+
/* istanbul ignore next: hard to test */
3132
if (socket.destroyed) {
3233
clearInterval(progressInterval);
3334
return;
3435
}
3536

3637
const lastUploaded = uploaded;
38+
/* istanbul ignore next: see #490 (occurs randomly!) */
3739
const headersSize = request._header ? Buffer.byteLength(request._header) : 0;
3840
uploaded = socket.bytesWritten - headersSize;
3941

40-
// Prevent the known issue of `bytesWritten` being larger than body size
42+
/* istanbul ignore next: see https://github.com/sindresorhus/got/pull/322#pullrequestreview-51647813 (no proof) */
4143
if (uploadBodySize && uploaded > uploadBodySize) {
4244
uploaded = uploadBodySize;
4345
}

‎source/request-as-event-emitter.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
2+
/* istanbul ignore next: compatibility reason */
3+
const URLGlobal = typeof URL === 'undefined' ? require('url').URL : URL; // TODO: Use the `URL` global when targeting Node.js 10
24
const EventEmitter = require('events');
35
const http = require('http');
46
const https = require('https');
5-
const URLGlobal = typeof URL === 'undefined' ? require('url').URL : URL; // TODO: Use the `URL` global when targeting Node.js 10
67
const urlLib = require('url');
78
const CacheableRequest = require('cacheable-request');
89
const is = require('@sindresorhus/is');
@@ -38,6 +39,7 @@ module.exports = options => {
3839
options.agent = agents[protocolName] || options.agent;
3940
}
4041

42+
/* istanbul ignore next: electron.net is broken */
4143
if (options.useElectronNet && process.versions.electron) {
4244
const electron = global['require']('electron'); // eslint-disable-line dot-notation
4345
fn = electron.net || electron.remote.net;

‎source/timed-out.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function addTimeout(delay, callback, ...args) {
1212
const timeout = setTimeout(
1313
() => {
1414
immediate = setImmediate(callback, delay, ...args);
15+
/* istanbul ignore next: added in node v9.7.0 */
1516
if (immediate.unref) {
16-
// Added in node v9.7.0
1717
immediate.unref();
1818
}
1919
},
@@ -27,6 +27,7 @@ function addTimeout(delay, callback, ...args) {
2727
}
2828

2929
module.exports = (request, options) => {
30+
/* istanbul ignore next: this makes sure timed-out isn't called twice */
3031
if (request[reentry]) {
3132
return;
3233
}
@@ -68,6 +69,7 @@ module.exports = (request, options) => {
6869

6970
if (delays.lookup !== undefined && !request.socketPath && !net.isIP(hostname || host)) {
7071
request.once('socket', socket => {
72+
/* istanbul ignore next: hard to test */
7173
if (socket.connecting) {
7274
const cancelTimeout = addTimeout(
7375
delays.lookup,
@@ -82,6 +84,7 @@ module.exports = (request, options) => {
8284

8385
if (delays.connect !== undefined) {
8486
request.once('socket', socket => {
87+
/* istanbul ignore next: hard to test */
8588
if (socket.connecting) {
8689
const timeConnect = () => {
8790
const cancelTimeout = addTimeout(
@@ -106,6 +109,7 @@ module.exports = (request, options) => {
106109

107110
if (delays.secureConnect !== undefined && options.protocol === 'https:') {
108111
request.once('socket', socket => {
112+
/* istanbul ignore next: hard to test */
109113
if (socket.connecting) {
110114
socket.once('connect', () => {
111115
const cancelTimeout = addTimeout(
@@ -131,7 +135,7 @@ module.exports = (request, options) => {
131135
cancelers.push(cancelTimeout);
132136
return cancelTimeout;
133137
};
134-
138+
/* istanbul ignore next: hard to test */
135139
if (socket.connecting) {
136140
socket.once('connect', () => {
137141
request.once('upload-complete', timeRequest());

‎test/stream.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ test('proxying headers works', async t => {
127127

128128
await server.listen(server.port);
129129

130-
const {headers} = await got(server.url);
130+
const {headers, body} = await got(server.url);
131131
t.is(headers.unicorn, 'rainbow');
132132
t.is(headers['content-encoding'], undefined);
133+
t.is(body, 'ok');
133134

134135
await server.close();
135136
});
@@ -164,3 +165,19 @@ test('throws when trying to proxy through a closed stream', async t => {
164165
await got(server.url);
165166
await server.close();
166167
});
168+
169+
test('proxies content-encoding header when options.decompress is false', async t => {
170+
const server = await createServer();
171+
172+
server.on('/', (request, response) => {
173+
got.stream(s.url, {decompress: false}).pipe(response);
174+
});
175+
176+
await server.listen(server.port);
177+
178+
const {headers} = await got(server.url);
179+
t.is(headers.unicorn, 'rainbow');
180+
t.is(headers['content-encoding'], 'gzip');
181+
182+
await server.close();
183+
});

0 commit comments

Comments
 (0)
Please sign in to comment.