aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.test.js
blob: 989e2bc562c78f74b0167c3e0aed8422522ef71b (plain)
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
130
131
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
 * MIT Licensed
 */

/**
 * Test dependencies.
 */

var builder = require('../../bin/builder')
  , common = require('./builder.common')
  , should = require('should');

/**
 * Tests.
 */

module.exports = {

  'version number': function () {
    builder.version.should().match(/([0-9]+)\.([0-9]+)\.([0-9]+)/);
    builder.version.should().equal(require('../../lib/io').version);
  },

  'production build LOC': function () {
    builder(function (err, result) {
      should.strictEqual(err, null)

      var lines = result.split('\n');
      lines.length.should().be.below(5);
      lines[0].should().match(/production/gi);
      Buffer.byteLength(result).should().be.below(43000);
    });
  },

  'development build LOC': function () {
    builder({ minify: false }, function (err, result) {
      should.strictEqual(err, null)

      var lines = result.split('\n');
      lines.length.should().be.above(5);
      lines[0].should().match(/development/gi);
      Buffer.byteLength(result).should().be.above(35000);
    });
  },

  'default builds': function () {
    builder(function (err, result) {
      should.strictEqual(err, null);

      var io = common.execute(result).io
        , transports = Object.keys(io.Transport)
        , defaults = Object.keys(builder.transports);

      /* XHR transport is private, but still available */
      transports.length.should().be.equal(defaults.length + 1);

      defaults.forEach(function (transport) {
        transports.indexOf(transport).should().be.above(-1);
      })
    });
  },

  'custom build': function () {
    builder(['websocket'], function (err, result) {
      should.strictEqual(err, null);

      var io = common.execute(result).io
        , transports = Object.keys(io.Transport);

      transports.should().have.length(1);
      transports[0].should().eql('websocket');
    });
  },

  'custom code': function () {
    var custom = 'var hello = "world";';
    builder({ custom: [custom], minify: false }, function (err, result) {
      should.strictEqual(err, null);

      result.should().include.string(custom);
    });
  },

  'node if': function () {
    var custom = '// if node \nvar hello = "world";\n'
      + '// end node\nvar pew = "pew";';

    builder({ custom: [custom], minify: false }, function (err, result) {
      should.strictEqual(err, null);

      result.should().not.include.string(custom);
      result.should().not.include.string('// if node');
      result.should().not.include.string('// end node');
      result.should().not.include.string('"world"');

      result.should().include.string('var pew = "pew"');
    });
  },

  'preserve the encoding during minification': function () {
    builder(function (err, result) {
      should.strictEqual(err, null);

      result.should().match(/(\\ufffd)/g);
    })
  },

  'globals': function () {
    builder(function (err, result) {
      should.strictEqual(err, null);

      var io = common.execute(result)
        , env = common.env()
        , allowed = ['io', 'swfobject', 'WEB_SOCKET_DISABLE_AUTO_INITIALIZATION'];

      Array.prototype.push.apply(allowed, Object.keys(env));

      Object.keys(io).forEach(function (global) {
        var index = allowed.indexOf(global);

        // the global is not allowed!
        if (!~index) {
          throw new Error('Global leak: ' + global);
        }
      });
    })
  }

};