Blame view

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