UNPKG

3.08 kBJavaScriptView Raw
1var assert = require('assert').strict,
2 ua = require('../scripts/util/useragent'),
3 opts = require('../scripts/util/downloadoptions');
4
5
6describe('util', function() {
7 describe('downloadoptions', function() {
8 describe('without a proxy', function() {
9 it('should look as we expect', function() {
10 var expected = {
11 strictSSL: true,
12 timeout: 60000,
13 headers: {
14 'User-Agent': ua(),
15 },
16 };
17
18 assert.deepStrictEqual(opts(), expected);
19 });
20 });
21
22 describe('with an npm config proxy', function() {
23 var proxy = 'http://test.proxy:1234';
24
25 before(function() {
26 process.env.npm_config_proxy = proxy;
27 });
28
29 after(function() {
30 delete process.env.npm_config_proxy;
31 });
32
33 it('should look as we expect', function() {
34 var expected = {
35 strictSSL: true,
36 proxy: proxy,
37 timeout: 60000,
38 headers: {
39 'User-Agent': ua(),
40 },
41 };
42
43 assert.deepStrictEqual(opts(), expected);
44 });
45 });
46
47 describe('with an env proxy proxy', function() {
48 var proxy = 'http://test.proxy:1234';
49
50 before(function() {
51 process.env.HTTP_PROXY = proxy;
52 });
53
54 after(function() {
55 delete process.env.HTTP_PROXY;
56 });
57
58 it('should look as we expect', function() {
59 var expected = {
60 strictSSL: true,
61 timeout: 60000,
62 headers: {
63 'User-Agent': ua(),
64 },
65 };
66
67 assert.deepStrictEqual(opts(), expected);
68 });
69 });
70
71 describe('with SASS_REJECT_UNAUTHORIZED set to false', function() {
72 beforeEach(function() {
73 process.env.SASS_REJECT_UNAUTHORIZED = '0';
74 });
75
76 it('should look as we expect', function() {
77 var expected = {
78 strictSSL: false,
79 timeout: 60000,
80 headers: {
81 'User-Agent': ua(),
82 },
83 };
84
85 assert.deepStrictEqual(opts(), expected);
86 });
87 });
88
89 describe('with SASS_REJECT_UNAUTHORIZED set to true', function() {
90 beforeEach(function() {
91 process.env.SASS_REJECT_UNAUTHORIZED = '1';
92 });
93
94 it('should look as we expect', function() {
95 var expected = {
96 strictSSL: true,
97 timeout: 60000,
98 headers: {
99 'User-Agent': ua(),
100 },
101 };
102
103 assert.deepStrictEqual(opts(), expected);
104 });
105 });
106
107 describe('with npm_config_sass_reject_unauthorized set to true', function() {
108 beforeEach(function() {
109 process.env.npm_config_sass_reject_unauthorized = true;
110 });
111
112 it('should look as we expect', function() {
113 var expected = {
114 strictSSL: true,
115 timeout: 60000,
116 headers: {
117 'User-Agent': ua(),
118 },
119 };
120
121 assert.deepStrictEqual(opts(), expected);
122 });
123
124 afterEach(function() {
125 process.env.npm_config_sass_reject_unauthorized = undefined;
126 });
127 });
128 });
129});