UNPKG

6.04 kBJavaScriptView Raw
1var assert = require('assert'),
2 sass = process.env.NODESASS_COV
3 ? require('../lib-cov/extensions')
4 : require('../lib/extensions');
5
6describe('runtime parameters', function() {
7 var pkg = require('../package'),
8 // Let's use JSON to fake a deep copy
9 savedArgv = JSON.stringify(process.argv),
10 savedEnv = JSON.stringify(process.env);
11
12 afterEach(function() {
13 process.argv = JSON.parse(savedArgv);
14 process.env = JSON.parse(savedEnv);
15 delete pkg.nodeSassConfig;
16 });
17
18 describe('configuration precedence should be respected', function() {
19
20 describe('SASS_BINARY_NAME', function() {
21 beforeEach(function() {
22 process.argv.push('--sass-binary-name', 'aaa');
23 process.env.SASS_BINARY_NAME = 'bbb';
24 process.env.npm_config_sass_binary_name = 'ccc';
25 pkg.nodeSassConfig = { binaryName: 'ddd' };
26 });
27
28 it('command line argument', function() {
29 assert.equal(sass.getBinaryName(), 'aaa_binding.node');
30 });
31
32 it('environment variable', function() {
33 process.argv = [];
34 assert.equal(sass.getBinaryName(), 'bbb_binding.node');
35 });
36
37 it('npm config variable', function() {
38 process.argv = [];
39 process.env.SASS_BINARY_NAME = null;
40 assert.equal(sass.getBinaryName(), 'ccc_binding.node');
41 });
42
43 it('package.json', function() {
44 process.argv = [];
45 process.env.SASS_BINARY_NAME = null;
46 process.env.npm_config_sass_binary_name = null;
47 assert.equal(sass.getBinaryName(), 'ddd_binding.node');
48 });
49 });
50
51 describe('SASS_BINARY_SITE', function() {
52 beforeEach(function() {
53 process.argv.push('--sass-binary-site', 'http://aaa.example.com:9999');
54 process.env.SASS_BINARY_SITE = 'http://bbb.example.com:8888';
55 process.env.npm_config_sass_binary_site = 'http://ccc.example.com:7777';
56 pkg.nodeSassConfig = { binarySite: 'http://ddd.example.com:6666' };
57 });
58
59 it('command line argument', function() {
60 var URL = 'http://aaa.example.com:9999';
61 assert.equal(sass.getBinaryUrl().substr(0, URL.length), URL);
62 });
63
64 it('environment variable', function() {
65 process.argv = [];
66 var URL = 'http://bbb.example.com:8888';
67 assert.equal(sass.getBinaryUrl().substr(0, URL.length), URL);
68 });
69
70 it('npm config variable', function() {
71 process.argv = [];
72 process.env.SASS_BINARY_SITE = null;
73 var URL = 'http://ccc.example.com:7777';
74 assert.equal(sass.getBinaryUrl().substr(0, URL.length), URL);
75 });
76
77 it('package.json', function() {
78 process.argv = [];
79 process.env.SASS_BINARY_SITE = null;
80 process.env.npm_config_sass_binary_site = null;
81 var URL = 'http://ddd.example.com:6666';
82 assert.equal(sass.getBinaryUrl().substr(0, URL.length), URL);
83 });
84 });
85
86 describe('SASS_BINARY_DIR', function() {
87 beforeEach(function() {
88 process.argv.push('--sass-binary-dir', 'aaa');
89 process.env.SASS_BINARY_DIR = 'bbb';
90 process.env.npm_config_sass_binary_dir = 'ccc';
91 pkg.nodeSassConfig = { binaryDir: 'ddd' };
92 });
93
94 it('command line argument', function() {
95 assert.equal(sass.getBinaryDir(), 'aaa');
96 });
97
98 it('environment variable', function() {
99 process.argv = [];
100 assert.equal(sass.getBinaryDir(), 'bbb');
101 });
102
103 it('npm config variable', function() {
104 process.argv = [];
105 process.env.SASS_BINARY_DIR = null;
106 assert.equal(sass.getBinaryDir(), 'ccc');
107 });
108
109 it('package.json', function() {
110 process.argv = [];
111 process.env.SASS_BINARY_DIR = null;
112 process.env.npm_config_sass_binary_dir = null;
113 assert.equal(sass.getBinaryDir(), 'ddd');
114 });
115 });
116
117 describe('SASS_BINARY_PATH', function() {
118 beforeEach(function() {
119 process.argv.push('--sass-binary-path', 'aaa_binding.node');
120 process.env.SASS_BINARY_PATH = 'bbb_binding.node';
121 process.env.npm_config_sass_binary_path = 'ccc_binding.node';
122 pkg.nodeSassConfig = { binaryPath: 'ddd_binding.node' };
123 });
124
125 it('command line argument', function() {
126 assert.equal(sass.getBinaryPath(), 'aaa_binding.node');
127 });
128
129 it('environment variable', function() {
130 process.argv = [];
131 assert.equal(sass.getBinaryPath(), 'bbb_binding.node');
132 });
133
134 it('npm config variable', function() {
135 process.argv = [];
136 process.env.SASS_BINARY_PATH = null;
137 assert.equal(sass.getBinaryPath(), 'ccc_binding.node');
138 });
139
140 it('package.json', function() {
141 process.argv = [];
142 process.env.SASS_BINARY_PATH = null;
143 process.env.npm_config_sass_binary_path = null;
144 assert.equal(sass.getBinaryPath(), 'ddd_binding.node');
145 });
146 });
147
148 });
149
150 describe.skip('Sass Binary Cache', function() {
151 var npmCacheDir;
152 before(function() {
153 npmCacheDir = process.env.npm_config_cache;
154 });
155
156 beforeEach(function() {
157 delete process.env.npm_config_sass_binary_cache;
158 });
159
160 it('npm config variable', function() {
161 var overridenCachePath = '/foo/bar/';
162 process.env.npm_config_sass_binary_cache = overridenCachePath;
163 assert.equal(sass.getCachePath(), overridenCachePath);
164 });
165
166 it('With no value, falls back to NPM cache', function() {
167 assert.equal(sass.getCachePath(), npmCacheDir);
168 });
169 });
170});
171
172// describe('library detection', function() {
173// it('should throw error when libsass binary is missing.', function() {
174// var sass = require(extensionsPath),
175// originalBin = sass.getBinaryPath(),
176// renamedBin = [originalBin, '_moved'].join('');
177
178// assert.throws(function() {
179// fs.renameSync(originalBin, renamedBin);
180// sass.getBinaryPath(true);
181// }, /The `libsass` binding was not found/);
182
183// fs.renameSync(renamedBin, originalBin);
184// });
185// });