binding.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*eslint new-cap: ["error", {"capIsNewExceptions": ["Color"]}]*/
  2. var assert = require('assert'),
  3. path = require('path'),
  4. etx = require('../lib/extensions'),
  5. binding = process.env.NODESASS_COV
  6. ? require('../lib-cov/binding')
  7. : require('../lib/binding');
  8. describe('binding', function() {
  9. describe('missing error', function() {
  10. it('should be useful', function() {
  11. process.env.SASS_BINARY_NAME = 'Linux-x64-48';
  12. assert.throws(
  13. function() { binding(etx); },
  14. function(err) {
  15. var re = new RegExp('Missing binding.*?\\' + path.sep + 'vendor\\' + path.sep);
  16. if ((err instanceof Error)) {
  17. return re.test(err);
  18. }
  19. }
  20. );
  21. });
  22. it('should list currently installed bindings', function() {
  23. assert.throws(
  24. function() { binding(etx); },
  25. function(err) {
  26. var etx = require('../lib/extensions');
  27. delete process.env.SASS_BINARY_NAME;
  28. if ((err instanceof Error)) {
  29. return err.message.indexOf(
  30. etx.getHumanEnvironment(etx.getBinaryName())
  31. ) !== -1;
  32. }
  33. }
  34. );
  35. });
  36. });
  37. describe('on unsupported environment', function() {
  38. describe('with an unsupported architecture', function() {
  39. var prevValue;
  40. beforeEach(function() {
  41. prevValue = process.arch;
  42. Object.defineProperty(process, 'arch', {
  43. value: 'foo',
  44. });
  45. });
  46. afterEach(function() {
  47. Object.defineProperty(process, 'arch', {
  48. value: prevValue,
  49. });
  50. });
  51. it('should error', function() {
  52. assert.throws(
  53. function() { binding(etx); },
  54. 'Node Sass does not yet support your current environment'
  55. );
  56. });
  57. it('should inform the user the architecture is unsupported', function() {
  58. assert.throws(
  59. function() { binding(etx); },
  60. 'Unsupported architecture (foo)'
  61. );
  62. });
  63. });
  64. describe('with an unsupported platform', function() {
  65. var prevValue;
  66. beforeEach(function() {
  67. prevValue = process.platform;
  68. Object.defineProperty(process, 'platform', {
  69. value: 'bar',
  70. });
  71. });
  72. afterEach(function() {
  73. Object.defineProperty(process, 'platform', {
  74. value: prevValue,
  75. });
  76. });
  77. it('should error', function() {
  78. assert.throws(
  79. function() { binding(etx); },
  80. 'Node Sass does not yet support your current environment'
  81. );
  82. });
  83. it('should inform the user the platform is unsupported', function() {
  84. assert.throws(
  85. function() { binding(etx); },
  86. 'Unsupported platform (bar)'
  87. );
  88. });
  89. });
  90. describe('with an unsupported runtime', function() {
  91. var prevValue;
  92. beforeEach(function() {
  93. prevValue = process.versions.modules;
  94. Object.defineProperty(process.versions, 'modules', {
  95. value: 'baz',
  96. });
  97. });
  98. afterEach(function() {
  99. Object.defineProperty(process.versions, 'modules', {
  100. value: prevValue,
  101. });
  102. });
  103. it('should error', function() {
  104. assert.throws(
  105. function() { binding(etx); },
  106. 'Node Sass does not yet support your current environment'
  107. );
  108. });
  109. it('should inform the user the runtime is unsupported', function() {
  110. assert.throws(
  111. function() { binding(etx); },
  112. 'Unsupported runtime (baz)'
  113. );
  114. });
  115. });
  116. });
  117. });