Initial commit
[yaffs-website] / node_modules / node-sass / test / runtime.js
1 var assert = require('assert'),
2   sass = process.env.NODESASS_COV
3       ? require('../lib-cov/extensions')
4       : require('../lib/extensions');
5
6 describe('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_PATH', function() {
87       beforeEach(function() {
88         process.argv.push('--sass-binary-path', 'aaa_binding.node');
89         process.env.SASS_BINARY_PATH = 'bbb_binding.node';
90         process.env.npm_config_sass_binary_path = 'ccc_binding.node';
91         pkg.nodeSassConfig = { binaryPath: 'ddd_binding.node' };
92       });
93
94       it('command line argument', function() {
95         assert.equal(sass.getBinaryPath(), 'aaa_binding.node');
96       });
97
98       it('environment variable', function() {
99         process.argv = [];
100         assert.equal(sass.getBinaryPath(), 'bbb_binding.node');
101       });
102
103       it('npm config variable', function() {
104         process.argv = [];
105         process.env.SASS_BINARY_PATH = null;
106         assert.equal(sass.getBinaryPath(), 'ccc_binding.node');
107       });
108
109       it('package.json', function() {
110         process.argv = [];
111         process.env.SASS_BINARY_PATH = null;
112         process.env.npm_config_sass_binary_path = null;
113         assert.equal(sass.getBinaryPath(), 'ddd_binding.node');
114       });
115     });
116
117   });
118
119   describe.skip('Sass Binary Cache', function() {
120     var npmCacheDir;
121     before(function() {
122       npmCacheDir = process.env.npm_config_cache;
123     });
124
125     beforeEach(function() {
126       delete process.env.npm_config_sass_binary_cache;
127     });
128
129     it('npm config variable', function() {
130       var overridenCachePath = '/foo/bar/';
131       process.env.npm_config_sass_binary_cache = overridenCachePath;
132       assert.equal(sass.getCachePath(), overridenCachePath);
133     });
134
135     it('With no value, falls back to NPM cache', function() {
136       assert.equal(sass.getCachePath(), npmCacheDir);
137     });
138   });
139 });
140
141 // describe('library detection', function() {
142 //   it('should throw error when libsass binary is missing.', function() {
143 //     var sass = require(extensionsPath),
144 //         originalBin = sass.getBinaryPath(),
145 //         renamedBin = [originalBin, '_moved'].join('');
146
147 //     assert.throws(function() {
148 //       fs.renameSync(originalBin, renamedBin);
149 //       sass.getBinaryPath(true);
150 //     }, /The `libsass` binding was not found/);
151
152 //     fs.renameSync(renamedBin, originalBin);
153 //   });
154 // });