1 var assert = require('assert'),
2 sass = process.env.NODESASS_COV
3 ? require('../lib-cov/extensions')
4 : require('../lib/extensions');
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);
12 afterEach(function() {
13 process.argv = JSON.parse(savedArgv);
14 process.env = JSON.parse(savedEnv);
15 delete pkg.nodeSassConfig;
18 describe('configuration precedence should be respected', function() {
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' };
28 it('command line argument', function() {
29 assert.equal(sass.getBinaryName(), 'aaa_binding.node');
32 it('environment variable', function() {
34 assert.equal(sass.getBinaryName(), 'bbb_binding.node');
37 it('npm config variable', function() {
39 process.env.SASS_BINARY_NAME = null;
40 assert.equal(sass.getBinaryName(), 'ccc_binding.node');
43 it('package.json', function() {
45 process.env.SASS_BINARY_NAME = null;
46 process.env.npm_config_sass_binary_name = null;
47 assert.equal(sass.getBinaryName(), 'ddd_binding.node');
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' };
59 it('command line argument', function() {
60 var URL = 'http://aaa.example.com:9999';
61 assert.equal(sass.getBinaryUrl().substr(0, URL.length), URL);
64 it('environment variable', function() {
66 var URL = 'http://bbb.example.com:8888';
67 assert.equal(sass.getBinaryUrl().substr(0, URL.length), URL);
70 it('npm config variable', function() {
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);
77 it('package.json', function() {
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);
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' };
94 it('command line argument', function() {
95 assert.equal(sass.getBinaryPath(), 'aaa_binding.node');
98 it('environment variable', function() {
100 assert.equal(sass.getBinaryPath(), 'bbb_binding.node');
103 it('npm config variable', function() {
105 process.env.SASS_BINARY_PATH = null;
106 assert.equal(sass.getBinaryPath(), 'ccc_binding.node');
109 it('package.json', function() {
111 process.env.SASS_BINARY_PATH = null;
112 process.env.npm_config_sass_binary_path = null;
113 assert.equal(sass.getBinaryPath(), 'ddd_binding.node');
119 describe.skip('Sass Binary Cache', function() {
122 npmCacheDir = process.env.npm_config_cache;
125 beforeEach(function() {
126 delete process.env.npm_config_sass_binary_cache;
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);
135 it('With no value, falls back to NPM cache', function() {
136 assert.equal(sass.getCachePath(), npmCacheDir);
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('');
147 // assert.throws(function() {
148 // fs.renameSync(originalBin, renamedBin);
149 // sass.getBinaryPath(true);
150 // }, /The `libsass` binding was not found/);
152 // fs.renameSync(renamedBin, originalBin);