Initial commit
[yaffs-website] / node_modules / node-sass / test / scripts / util / proxy.js
1 var assert = require('assert'),
2   proxy = require('../../../scripts/util/proxy');
3
4 describe('proxy', function() {
5   var oldEnvironment;
6
7   beforeEach(function() {
8     oldEnvironment = process.env;
9   });
10
11   afterEach(function() {
12     process.env = oldEnvironment;
13   });
14
15   describe('without an npm proxy config', function() {
16     delete process.env.npm_config_https_proxy;
17     delete process.env.npm_config_proxy;
18     delete process.env.npm_config_http_proxy;
19
20     it('should return an empty string', function() {
21       assert.strictEqual('', proxy());
22     });
23
24     it('should ignore system proxy environment variables', function() {
25       process.env.HTTPS_PROXY = 'http://https_proxy.com';
26       process.env.PROXY = 'http://proxy.com';
27       process.env.HTTP_PROXY = 'http://http_proxy.com';
28
29       assert.strictEqual('', proxy());
30     });
31   });
32
33   describe('with an npm proxy config', function() {
34     beforeEach(function() {
35       process.env.npm_config_https_proxy = 'http://https_proxy.com';
36       process.env.npm_config_proxy = 'http://proxy.com';
37       process.env.npm_config_http_proxy = 'http://http_proxy.com';
38     });
39
40     describe('https_proxy', function() {
41       it('should have the highest precedence', function() {
42         assert.strictEqual(process.env.npm_config_https_proxy, proxy());
43       });
44     });
45
46     describe('proxy', function() {
47       it('should have the higher precedence than https_proxy', function() {
48         assert.strictEqual(process.env.npm_config_https_proxy, proxy());
49         delete process.env.npm_config_https_proxy;
50
51         assert.strictEqual(process.env.npm_config_proxy, proxy());
52       });
53
54       it('should have the lower precedence than http_proxy', function() {
55         delete process.env.npm_config_https_proxy;
56
57         assert.strictEqual(process.env.npm_config_proxy, proxy());
58         delete process.env.npm_config_proxy;
59
60         assert.strictEqual(process.env.npm_config_http_proxy, proxy());
61       });
62     });
63
64     describe('http_proxy', function() {
65       it('should have the lowest precedence', function() {
66         assert.strictEqual(process.env.npm_config_https_proxy, proxy());
67         delete process.env.npm_config_https_proxy;
68
69         assert.strictEqual(process.env.npm_config_proxy, proxy());
70         delete process.env.npm_config_proxy;
71
72         assert.strictEqual(process.env.npm_config_http_proxy, proxy());
73       });
74     });
75   });
76 });