• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Rob--W / proxy-from-env / 21345883438

26 Jan 2026 04:01AM UTC coverage: 98.56% (-0.4%) from 98.988%
21345883438

push

github

Rob--W
CI: Run tests with all supported Node.js versions

And also fix up mistake from b67a31e03
that prevented tests from running at all due to the removed
test-old-node / test-recent-node jobs (replaced by one test-node).

80 of 81 branches covered (98.77%)

616 of 625 relevant lines covered (98.56%)

70.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.28
/test.js
1
/* eslint max-statements:0 */
2✔
2
'use strict';
2✔
3

2✔
4
import {describe, it} from 'node:test';
2✔
5
import assert from 'node:assert';
2✔
6
import {parse as parseUrl} from 'node:url';
2✔
7

2✔
8
import {getProxyForUrl} from 'proxy-from-env';
2✔
9

2✔
10
// Runs the callback with process.env temporarily set to env.
2✔
11
function runWithEnv(env, callback) {
322✔
12
  var originalEnv = process.env;
322✔
13
  process.env = env;
322✔
14
  try {
322✔
15
    callback();
322✔
16
  } finally {
322✔
17
    process.env = originalEnv;
322✔
18
  }
322✔
19
}
322✔
20

2✔
21
// Defines a test case that checks whether getProxyForUrl(input) === expected.
2✔
22
function testProxyUrl(env, expected, input) {
322✔
23
  assert(typeof env === 'object' && env !== null);
322✔
24
  // Copy object to make sure that the in param does not get modified between
322✔
25
  // the call of this function and the use of it below.
322✔
26
  env = JSON.parse(JSON.stringify(env));
322✔
27

322✔
28
  var title = 'getProxyForUrl(' + JSON.stringify(input) + ')' +
322✔
29
     ' === ' + JSON.stringify(expected);
322✔
30

322✔
31
  // Save call stack for later use.
322✔
32
  var stack = {};
322✔
33
  Error.captureStackTrace(stack, testProxyUrl);
322✔
34
  // Only use the last stack frame because that shows where this function is
322✔
35
  // called, and that is sufficient for our purpose. No need to flood the logs
322✔
36
  // with an uninteresting stack trace.
322✔
37
  stack = stack.stack.split('\n', 2)[1];
322✔
38

322✔
39
  it(title, function() {
322✔
40
    var actual;
322✔
41
    runWithEnv(env, function() {
322✔
42
      actual = getProxyForUrl(input);
322✔
43
    });
322✔
44
    if (expected === actual) {
322✔
45
      return;  // Good!
322✔
46
    }
322!
47
    try {
×
48
      assert.strictEqual(expected, actual); // Create a formatted error message.
×
49
      // Should not happen because previously we determined expected !== actual.
×
50
      throw new Error('assert.strictEqual passed. This is impossible!');
×
51
    } catch (e) {
×
52
      // Use the original stack trace, so we can see a helpful line number.
×
53
      e.stack = e.message + stack;
×
54
      throw e;
×
55
    }
×
56
  });
322✔
57
}
322✔
58

2✔
59
describe('getProxyForUrl', function() {
2✔
60
  describe('No proxy variables', function() {
2✔
61
    var env = {};
2✔
62
    testProxyUrl(env, '', 'http://example.com');
2✔
63
    testProxyUrl(env, '', 'https://example.com');
2✔
64
    testProxyUrl(env, '', 'ftp://example.com');
2✔
65
  });
2✔
66

2✔
67
  describe('Invalid URLs', function() {
2✔
68
    var env = {};
2✔
69
    env.ALL_PROXY = 'http://unexpected.proxy';
2✔
70
    testProxyUrl(env, '', 'bogus');
2✔
71
    testProxyUrl(env, '', '//example.com');
2✔
72
    testProxyUrl(env, '', '://example.com');
2✔
73
    testProxyUrl(env, '', '://');
2✔
74
    testProxyUrl(env, '', '/path');
2✔
75
    testProxyUrl(env, '', '');
2✔
76
    testProxyUrl(env, '', 'http:');
2✔
77
    testProxyUrl(env, '', 'http:/');
2✔
78
    testProxyUrl(env, '', 'http://');
2✔
79
    testProxyUrl(env, '', 'prototype://');
2✔
80
    testProxyUrl(env, '', 'hasOwnProperty://');
2✔
81
    testProxyUrl(env, '', '__proto__://');
2✔
82
    testProxyUrl(env, '', undefined);
2✔
83
    testProxyUrl(env, '', null);
2✔
84
    testProxyUrl(env, '', {});
2✔
85
    testProxyUrl(env, '', {host: 'x', protocol: 1});
2✔
86
    testProxyUrl(env, '', {host: 1, protocol: 'x'});
2✔
87

2✔
88
    describe('difference between url.parse and WHATWG URL', function() {
2✔
89
      // Node 24 and later raise the following warning when url.parse is used:
2✔
90
      //
2✔
91
      // (node:11623) [DEP0169] DeprecationWarning: `url.parse()` behavior is
2✔
92
      // not standardized and prone to errors that have security implications.
2✔
93
      // Use the WHATWG URL API instead. CVEs are not issued for `url.parse()`
2✔
94
      // vulnerabilities.
2✔
95
      //
2✔
96
      // The above refers to https://hackerone.com/reports/678487 which shows
2✔
97
      // that a bare percentage sign is parsed inconsistently:
2✔
98
      // - `url.parse` splits hosts.
2✔
99
      // - WHATWG `URL` constructor raised an error.
2✔
100
      //
2✔
101
      // This test case shows the difference.
2✔
102
      //
2✔
103
      // For comparison:
2✔
104
      // - curl (8.17.0) refuses to connect:
2✔
105
      //   $ http_proxy=http://localhost:1337 curl http://bad%
2✔
106
      //   curl:(3) URL rejected: Bad hostname
2✔
107
      // - wget (GNU wget 1.25.0) passes "bad%" as Host header:
2✔
108
      //   $ http_proxy=http://localhost:1337 wget http://bad%
2✔
109
      //   (nc -l 1337 receives request with "bad% as Host header)
2✔
110
      // - Python (3.13.11) passes "bad%" as Host header:
2✔
111
      //   $ http_proxy=http://localhost:1337 python3 -c \
2✔
112
      //       'import urllib.request;urllib.request.urlopen("http://bad%")'
2✔
113
      //   (nc -l 1337 receives request with "bad% as Host header)
2✔
114

2✔
115
      // A canonical URL does not have a single "%".
2✔
116
      var badUrl = 'http://bad%';
2✔
117

2✔
118
      // proxy-from-env@1.1.0 and earlier accepted bad URLs:
2✔
119
      testProxyUrl(env, 'http://unexpected.proxy', parseUrl(badUrl));
2✔
120

2✔
121
      // Sanity check: WHATWG URL constructor rejects badUrl.
2✔
122
      assert(!URL.canParse(badUrl));
2✔
123

2✔
124
      // Verify current proxy-from-env behavior. Currently same as 1.1.0:
2✔
125
      testProxyUrl(env, 'http://unexpected.proxy', badUrl);
2✔
126
    });
2✔
127
  });
2✔
128

2✔
129
  describe('http_proxy and HTTP_PROXY', function() {
2✔
130
    var env = {};
2✔
131
    env.HTTP_PROXY = 'http://http-proxy';
2✔
132

2✔
133
    testProxyUrl(env, '', 'https://example');
2✔
134
    testProxyUrl(env, 'http://http-proxy', 'http://example');
2✔
135
    testProxyUrl(env, 'http://http-proxy', parseUrl('http://example'));
2✔
136

2✔
137
    // eslint-disable-next-line camelcase
2✔
138
    env.http_proxy = 'http://priority';
2✔
139
    testProxyUrl(env, 'http://priority', 'http://example');
2✔
140
  });
2✔
141

2✔
142
  describe('http_proxy with non-sensical value', function() {
2✔
143
    var env = {};
2✔
144
    // Crazy values should be passed as-is. It is the responsibility of the
2✔
145
    // one who launches the application that the value makes sense.
2✔
146
    // TODO: Should we be stricter and perform validation?
2✔
147
    env.HTTP_PROXY = 'Crazy \n!() { ::// }';
2✔
148
    testProxyUrl(env, 'Crazy \n!() { ::// }', 'http://wow');
2✔
149

2✔
150
    // The implementation assumes that the HTTP_PROXY environment variable is
2✔
151
    // somewhat reasonable, and if the scheme is missing, it is added.
2✔
152
    // Garbage in, garbage out some would say...
2✔
153
    env.HTTP_PROXY = 'crazy without colon slash slash';
2✔
154
    testProxyUrl(env, 'http://crazy without colon slash slash', 'http://wow');
2✔
155
  });
2✔
156

2✔
157
  describe('https_proxy and HTTPS_PROXY', function() {
2✔
158
    var env = {};
2✔
159
    // Assert that there is no fall back to http_proxy
2✔
160
    env.HTTP_PROXY = 'http://unexpected.proxy';
2✔
161
    testProxyUrl(env, '', 'https://example');
2✔
162

2✔
163
    env.HTTPS_PROXY = 'http://https-proxy';
2✔
164
    testProxyUrl(env, 'http://https-proxy', 'https://example');
2✔
165

2✔
166
    // eslint-disable-next-line camelcase
2✔
167
    env.https_proxy = 'http://priority';
2✔
168
    testProxyUrl(env, 'http://priority', 'https://example');
2✔
169
  });
2✔
170

2✔
171
  describe('ftp_proxy', function() {
2✔
172
    var env = {};
2✔
173
    // Something else than http_proxy / https, as a sanity check.
2✔
174
    env.FTP_PROXY = 'http://ftp-proxy';
2✔
175

2✔
176
    testProxyUrl(env, 'http://ftp-proxy', 'ftp://example');
2✔
177
    testProxyUrl(env, '', 'ftps://example');
2✔
178
  });
2✔
179

2✔
180
  describe('all_proxy', function() {
2✔
181
    var env = {};
2✔
182
    env.ALL_PROXY = 'http://catch-all';
2✔
183
    testProxyUrl(env, 'http://catch-all', 'https://example');
2✔
184

2✔
185
    // eslint-disable-next-line camelcase
2✔
186
    env.all_proxy = 'http://priority';
2✔
187
    testProxyUrl(env, 'http://priority', 'https://example');
2✔
188
  });
2✔
189

2✔
190
  describe('all_proxy without scheme', function() {
2✔
191
    var env = {};
2✔
192
    env.ALL_PROXY = 'noscheme';
2✔
193
    testProxyUrl(env, 'http://noscheme', 'http://example');
2✔
194
    testProxyUrl(env, 'https://noscheme', 'https://example');
2✔
195

2✔
196
    // The module does not impose restrictions on the scheme.
2✔
197
    testProxyUrl(env, 'bogus-scheme://noscheme', 'bogus-scheme://example');
2✔
198

2✔
199
    // But the URL should still be valid.
2✔
200
    testProxyUrl(env, '', 'bogus');
2✔
201
  });
2✔
202

2✔
203
  describe('no_proxy empty', function() {
2✔
204
    var env = {};
2✔
205
    env.HTTPS_PROXY = 'http://proxy';
2✔
206

2✔
207
    // NO_PROXY set but empty.
2✔
208
    env.NO_PROXY = '';
2✔
209
    testProxyUrl(env, 'http://proxy', 'https://example');
2✔
210

2✔
211
    // No entries in NO_PROXY (comma).
2✔
212
    env.NO_PROXY = ',';
2✔
213
    testProxyUrl(env, 'http://proxy', 'https://example');
2✔
214

2✔
215
    // No entries in NO_PROXY (whitespace).
2✔
216
    env.NO_PROXY = ' ';
2✔
217
    testProxyUrl(env, 'http://proxy', 'https://example');
2✔
218

2✔
219
    // No entries in NO_PROXY (multiple whitespace / commas).
2✔
220
    env.NO_PROXY = ',\t,,,\n,  ,\r';
2✔
221
    testProxyUrl(env, 'http://proxy', 'https://example');
2✔
222
  });
2✔
223

2✔
224
  describe('no_proxy=example (single host)', function() {
2✔
225
    var env = {};
2✔
226
    env.HTTP_PROXY = 'http://proxy';
2✔
227

2✔
228
    env.NO_PROXY = 'example';
2✔
229
    testProxyUrl(env, '', 'http://example');
2✔
230
    testProxyUrl(env, '', 'http://example:80');
2✔
231
    testProxyUrl(env, '', 'http://example:0');
2✔
232
    testProxyUrl(env, '', 'http://example:1337');
2✔
233
    testProxyUrl(env, 'http://proxy', 'http://sub.example');
2✔
234
    testProxyUrl(env, 'http://proxy', 'http://prefexample');
2✔
235
    testProxyUrl(env, 'http://proxy', 'http://example.no');
2✔
236
    testProxyUrl(env, 'http://proxy', 'http://a.b.example');
2✔
237
    testProxyUrl(env, 'http://proxy', 'http://host/example');
2✔
238
  });
2✔
239

2✔
240
  describe('no_proxy=sub.example (subdomain)', function() {
2✔
241
    var env = {};
2✔
242
    env.HTTP_PROXY = 'http://proxy';
2✔
243

2✔
244
    env.NO_PROXY = 'sub.example';
2✔
245
    testProxyUrl(env, 'http://proxy', 'http://example');
2✔
246
    testProxyUrl(env, 'http://proxy', 'http://example:80');
2✔
247
    testProxyUrl(env, 'http://proxy', 'http://example:0');
2✔
248
    testProxyUrl(env, 'http://proxy', 'http://example:1337');
2✔
249
    testProxyUrl(env, '', 'http://sub.example');
2✔
250
    testProxyUrl(env, 'http://proxy', 'http://no.sub.example');
2✔
251
    testProxyUrl(env, 'http://proxy', 'http://sub-example');
2✔
252
    testProxyUrl(env, 'http://proxy', 'http://example.sub');
2✔
253
  });
2✔
254

2✔
255
  describe('no_proxy=example:80 (host + port)', function() {
2✔
256
    var env = {};
2✔
257
    env.HTTP_PROXY = 'http://proxy';
2✔
258

2✔
259
    env.NO_PROXY = 'example:80';
2✔
260
    testProxyUrl(env, '', 'http://example');
2✔
261
    testProxyUrl(env, '', 'http://example:80');
2✔
262
    testProxyUrl(env, '', 'http://example:0');
2✔
263
    testProxyUrl(env, 'http://proxy', 'http://example:1337');
2✔
264
    testProxyUrl(env, 'http://proxy', 'http://sub.example');
2✔
265
    testProxyUrl(env, 'http://proxy', 'http://prefexample');
2✔
266
    testProxyUrl(env, 'http://proxy', 'http://example.no');
2✔
267
    testProxyUrl(env, 'http://proxy', 'http://a.b.example');
2✔
268
  });
2✔
269

2✔
270
  describe('no_proxy=.example (host suffix)', function() {
2✔
271
    var env = {};
2✔
272
    env.HTTP_PROXY = 'http://proxy';
2✔
273

2✔
274
    env.NO_PROXY = '.example';
2✔
275
    testProxyUrl(env, 'http://proxy', 'http://example');
2✔
276
    testProxyUrl(env, 'http://proxy', 'http://example:80');
2✔
277
    testProxyUrl(env, 'http://proxy', 'http://example:1337');
2✔
278
    testProxyUrl(env, '', 'http://sub.example');
2✔
279
    testProxyUrl(env, '', 'http://sub.example:80');
2✔
280
    testProxyUrl(env, '', 'http://sub.example:1337');
2✔
281
    testProxyUrl(env, 'http://proxy', 'http://prefexample');
2✔
282
    testProxyUrl(env, 'http://proxy', 'http://example.no');
2✔
283
    testProxyUrl(env, '', 'http://a.b.example');
2✔
284
  });
2✔
285

2✔
286
  describe('no_proxy=*', function() {
2✔
287
    var env = {};
2✔
288
    env.HTTP_PROXY = 'http://proxy';
2✔
289
    env.NO_PROXY = '*';
2✔
290
    testProxyUrl(env, '', 'http://example.com');
2✔
291
  });
2✔
292

2✔
293
  describe('no_proxy=*.example (host suffix with *.)', function() {
2✔
294
    var env = {};
2✔
295
    env.HTTP_PROXY = 'http://proxy';
2✔
296

2✔
297
    env.NO_PROXY = '*.example';
2✔
298
    testProxyUrl(env, 'http://proxy', 'http://example');
2✔
299
    testProxyUrl(env, 'http://proxy', 'http://example:80');
2✔
300
    testProxyUrl(env, 'http://proxy', 'http://example:1337');
2✔
301
    testProxyUrl(env, '', 'http://sub.example');
2✔
302
    testProxyUrl(env, '', 'http://sub.example:80');
2✔
303
    testProxyUrl(env, '', 'http://sub.example:1337');
2✔
304
    testProxyUrl(env, 'http://proxy', 'http://prefexample');
2✔
305
    testProxyUrl(env, 'http://proxy', 'http://example.no');
2✔
306
    testProxyUrl(env, '', 'http://a.b.example');
2✔
307
  });
2✔
308

2✔
309
  describe('no_proxy=*example (substring suffix)', function() {
2✔
310
    var env = {};
2✔
311
    env.HTTP_PROXY = 'http://proxy';
2✔
312

2✔
313
    env.NO_PROXY = '*example';
2✔
314
    testProxyUrl(env, '', 'http://example');
2✔
315
    testProxyUrl(env, '', 'http://example:80');
2✔
316
    testProxyUrl(env, '', 'http://example:1337');
2✔
317
    testProxyUrl(env, '', 'http://sub.example');
2✔
318
    testProxyUrl(env, '', 'http://sub.example:80');
2✔
319
    testProxyUrl(env, '', 'http://sub.example:1337');
2✔
320
    testProxyUrl(env, '', 'http://prefexample');
2✔
321
    testProxyUrl(env, '', 'http://a.b.example');
2✔
322
    testProxyUrl(env, 'http://proxy', 'http://example.no');
2✔
323
    testProxyUrl(env, 'http://proxy', 'http://host/example');
2✔
324
  });
2✔
325

2✔
326
  describe('no_proxy=.*example (arbitrary wildcards are NOT supported)',
2✔
327
      function() {
2✔
328
    var env = {};
2✔
329
    env.HTTP_PROXY = 'http://proxy';
2✔
330

2✔
331
    env.NO_PROXY = '.*example';
2✔
332
    testProxyUrl(env, 'http://proxy', 'http://example');
2✔
333
    testProxyUrl(env, 'http://proxy', 'http://sub.example');
2✔
334
    testProxyUrl(env, 'http://proxy', 'http://sub.example');
2✔
335
    testProxyUrl(env, 'http://proxy', 'http://prefexample');
2✔
336
    testProxyUrl(env, 'http://proxy', 'http://x.prefexample');
2✔
337
    testProxyUrl(env, 'http://proxy', 'http://a.b.example');
2✔
338
  });
2✔
339

2✔
340
  describe('no_proxy=[::1],[::2]:80,10.0.0.1,10.0.0.2:80 (IP addresses)',
2✔
341
      function() {
2✔
342
    var env = {};
2✔
343
    env.HTTP_PROXY = 'http://proxy';
2✔
344

2✔
345
    env.NO_PROXY = '[::1],[::2]:80,10.0.0.1,10.0.0.2:80';
2✔
346
    testProxyUrl(env, '', 'http://[::1]/');
2✔
347
    testProxyUrl(env, '', 'http://[::1]:80/');
2✔
348
    testProxyUrl(env, '', 'http://[::1]:1337/');
2✔
349

2✔
350
    testProxyUrl(env, '', 'http://[::2]/');
2✔
351
    testProxyUrl(env, '', 'http://[::2]:80/');
2✔
352
    testProxyUrl(env, 'http://proxy', 'http://[::2]:1337/');
2✔
353

2✔
354
    testProxyUrl(env, '', 'http://10.0.0.1/');
2✔
355
    testProxyUrl(env, '', 'http://10.0.0.1:80/');
2✔
356
    testProxyUrl(env, '', 'http://10.0.0.1:1337/');
2✔
357

2✔
358
    testProxyUrl(env, '', 'http://10.0.0.2/');
2✔
359
    testProxyUrl(env, '', 'http://10.0.0.2:80/');
2✔
360
    testProxyUrl(env, 'http://proxy', 'http://10.0.0.2:1337/');
2✔
361
  });
2✔
362

2✔
363
  describe('no_proxy=127.0.0.1/32 (CIDR is NOT supported)', function() {
2✔
364
    var env = {};
2✔
365
    env.HTTP_PROXY = 'http://proxy';
2✔
366

2✔
367
    env.NO_PROXY = '127.0.0.1/32';
2✔
368
    testProxyUrl(env, 'http://proxy', 'http://127.0.0.1');
2✔
369
    testProxyUrl(env, 'http://proxy', 'http://127.0.0.1/32');
2✔
370
  });
2✔
371

2✔
372
  describe('no_proxy=127.0.0.1 does NOT match localhost', function() {
2✔
373
    var env = {};
2✔
374
    env.HTTP_PROXY = 'http://proxy';
2✔
375

2✔
376
    env.NO_PROXY = '127.0.0.1';
2✔
377
    testProxyUrl(env, '', 'http://127.0.0.1');
2✔
378
    // We're not performing DNS queries, so this shouldn't match.
2✔
379
    testProxyUrl(env, 'http://proxy', 'http://localhost');
2✔
380
  });
2✔
381

2✔
382
  describe('no_proxy with protocols that have a default port', function() {
2✔
383
    var env = {};
2✔
384
    env.WS_PROXY = 'http://ws';
2✔
385
    env.WSS_PROXY = 'http://wss';
2✔
386
    env.HTTP_PROXY = 'http://http';
2✔
387
    env.HTTPS_PROXY = 'http://https';
2✔
388
    env.GOPHER_PROXY = 'http://gopher';
2✔
389
    env.FTP_PROXY = 'http://ftp';
2✔
390
    env.ALL_PROXY = 'http://all';
2✔
391

2✔
392
    env.NO_PROXY = 'xxx:21,xxx:70,xxx:80,xxx:443';
2✔
393

2✔
394
    testProxyUrl(env, '', 'http://xxx');
2✔
395
    testProxyUrl(env, '', 'http://xxx:80');
2✔
396
    testProxyUrl(env, 'http://http', 'http://xxx:1337');
2✔
397

2✔
398
    testProxyUrl(env, '', 'ws://xxx');
2✔
399
    testProxyUrl(env, '', 'ws://xxx:80');
2✔
400
    testProxyUrl(env, 'http://ws', 'ws://xxx:1337');
2✔
401

2✔
402
    testProxyUrl(env, '', 'https://xxx');
2✔
403
    testProxyUrl(env, '', 'https://xxx:443');
2✔
404
    testProxyUrl(env, 'http://https', 'https://xxx:1337');
2✔
405

2✔
406
    testProxyUrl(env, '', 'wss://xxx');
2✔
407
    testProxyUrl(env, '', 'wss://xxx:443');
2✔
408
    testProxyUrl(env, 'http://wss', 'wss://xxx:1337');
2✔
409

2✔
410
    testProxyUrl(env, '', 'gopher://xxx');
2✔
411
    testProxyUrl(env, '', 'gopher://xxx:70');
2✔
412
    testProxyUrl(env, 'http://gopher', 'gopher://xxx:1337');
2✔
413

2✔
414
    testProxyUrl(env, '', 'ftp://xxx');
2✔
415
    testProxyUrl(env, '', 'ftp://xxx:21');
2✔
416
    testProxyUrl(env, 'http://ftp', 'ftp://xxx:1337');
2✔
417
  });
2✔
418

2✔
419
  describe('no_proxy should not be case-sensitive', function() {
2✔
420
    var env = {};
2✔
421
    env.HTTP_PROXY = 'http://proxy';
2✔
422
    env.NO_PROXY = 'XXX,YYY,ZzZ';
2✔
423

2✔
424
    testProxyUrl(env, '', 'http://xxx');
2✔
425
    testProxyUrl(env, '', 'http://XXX');
2✔
426
    testProxyUrl(env, '', 'http://yyy');
2✔
427
    testProxyUrl(env, '', 'http://YYY');
2✔
428
    testProxyUrl(env, '', 'http://ZzZ');
2✔
429
    testProxyUrl(env, '', 'http://zZz');
2✔
430
  });
2✔
431

2✔
432
  describe('NPM proxy configuration', function() {
2✔
433
    describe('npm_config_http_proxy should work', function() {
2✔
434
      var env = {};
2✔
435
      // eslint-disable-next-line camelcase
2✔
436
      env.npm_config_http_proxy = 'http://http-proxy';
2✔
437

2✔
438
      testProxyUrl(env, '', 'https://example');
2✔
439
      testProxyUrl(env, 'http://http-proxy', 'http://example');
2✔
440

2✔
441
      // eslint-disable-next-line camelcase
2✔
442
      env.npm_config_http_proxy = 'http://priority';
2✔
443
      testProxyUrl(env, 'http://priority', 'http://example');
2✔
444
    });
2✔
445
    // eslint-disable-next-line max-len
2✔
446
    describe('npm_config_http_proxy should take precedence over HTTP_PROXY and npm_config_proxy', function() {
2✔
447
      var env = {};
2✔
448
      // eslint-disable-next-line camelcase
2✔
449
      env.npm_config_http_proxy = 'http://http-proxy';
2✔
450
      // eslint-disable-next-line camelcase
2✔
451
      env.npm_config_proxy = 'http://unexpected-proxy';
2✔
452
      env.HTTP_PROXY = 'http://unexpected-proxy';
2✔
453

2✔
454
      testProxyUrl(env, 'http://http-proxy', 'http://example');
2✔
455
    });
2✔
456
    describe('npm_config_https_proxy should work', function() {
2✔
457
      var env = {};
2✔
458
      // eslint-disable-next-line camelcase
2✔
459
      env.npm_config_http_proxy = 'http://unexpected.proxy';
2✔
460
      testProxyUrl(env, '', 'https://example');
2✔
461

2✔
462
      // eslint-disable-next-line camelcase
2✔
463
      env.npm_config_https_proxy = 'http://https-proxy';
2✔
464
      testProxyUrl(env, 'http://https-proxy', 'https://example');
2✔
465

2✔
466
      // eslint-disable-next-line camelcase
2✔
467
      env.npm_config_https_proxy = 'http://priority';
2✔
468
      testProxyUrl(env, 'http://priority', 'https://example');
2✔
469
    });
2✔
470
    // eslint-disable-next-line max-len
2✔
471
    describe('npm_config_https_proxy should take precedence over HTTPS_PROXY and npm_config_proxy', function() {
2✔
472
      var env = {};
2✔
473
      // eslint-disable-next-line camelcase
2✔
474
      env.npm_config_https_proxy = 'http://https-proxy';
2✔
475
      // eslint-disable-next-line camelcase
2✔
476
      env.npm_config_proxy = 'http://unexpected-proxy';
2✔
477
      env.HTTPS_PROXY = 'http://unexpected-proxy';
2✔
478

2✔
479
      testProxyUrl(env, 'http://https-proxy', 'https://example');
2✔
480
    });
2✔
481
    describe('npm_config_proxy should work', function() {
2✔
482
      var env = {};
2✔
483
      // eslint-disable-next-line camelcase
2✔
484
      env.npm_config_proxy = 'http://http-proxy';
2✔
485
      testProxyUrl(env, 'http://http-proxy', 'http://example');
2✔
486
      testProxyUrl(env, 'http://http-proxy', 'https://example');
2✔
487

2✔
488
      // eslint-disable-next-line camelcase
2✔
489
      env.npm_config_proxy = 'http://priority';
2✔
490
      testProxyUrl(env, 'http://priority', 'http://example');
2✔
491
      testProxyUrl(env, 'http://priority', 'https://example');
2✔
492
    });
2✔
493
    // eslint-disable-next-line max-len
2✔
494
    describe('HTTP_PROXY and HTTPS_PROXY should take precedence over npm_config_proxy', function() {
2✔
495
      var env = {};
2✔
496
      env.HTTP_PROXY = 'http://http-proxy';
2✔
497
      env.HTTPS_PROXY = 'http://https-proxy';
2✔
498
      // eslint-disable-next-line camelcase
2✔
499
      env.npm_config_proxy = 'http://unexpected-proxy';
2✔
500
      testProxyUrl(env, 'http://http-proxy', 'http://example');
2✔
501
      testProxyUrl(env, 'http://https-proxy', 'https://example');
2✔
502
    });
2✔
503
    describe('npm_config_no_proxy should work', function() {
2✔
504
      var env = {};
2✔
505
      env.HTTP_PROXY = 'http://proxy';
2✔
506
      // eslint-disable-next-line camelcase
2✔
507
      env.npm_config_no_proxy = 'example';
2✔
508

2✔
509
      testProxyUrl(env, '', 'http://example');
2✔
510
      testProxyUrl(env, 'http://proxy', 'http://otherwebsite');
2✔
511
    });
2✔
512
    // eslint-disable-next-line max-len
2✔
513
    describe('npm_config_no_proxy should take precedence over NO_PROXY', function() {
2✔
514
      var env = {};
2✔
515
      env.HTTP_PROXY = 'http://proxy';
2✔
516
      env.NO_PROXY = 'otherwebsite';
2✔
517
      // eslint-disable-next-line camelcase
2✔
518
      env.npm_config_no_proxy = 'example';
2✔
519

2✔
520
      testProxyUrl(env, '', 'http://example');
2✔
521
      testProxyUrl(env, 'http://proxy', 'http://otherwebsite');
2✔
522
    });
2✔
523
  });
2✔
524
});
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc