runtime.js 5.0 KB

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