Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / test / node / builder.test.js
1 /*!
2  * socket.io-node
3  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
4  * MIT Licensed
5  */
6
7 /**
8  * Test dependencies.
9  */
10
11 var builder = require('../../bin/builder')
12   , common = require('./builder.common')
13   , should = require('should');
14
15 /**
16  * Tests.
17  */
18
19 module.exports = {
20
21   'version number': function () {
22     builder.version.should().match(/([0-9]+)\.([0-9]+)\.([0-9]+)/);
23     builder.version.should().equal(require('../../lib/io').version);
24   },
25
26   'production build LOC': function () {
27     builder(function (err, result) {
28       should.strictEqual(err, null)
29
30       var lines = result.split('\n');
31       lines.length.should().be.below(5);
32       lines[0].should().match(/production/gi);
33       Buffer.byteLength(result).should().be.below(43000);
34     });
35   },
36
37   'development build LOC': function () {
38     builder({ minify: false }, function (err, result) {
39       should.strictEqual(err, null)
40
41       var lines = result.split('\n');
42       lines.length.should().be.above(5);
43       lines[0].should().match(/development/gi);
44       Buffer.byteLength(result).should().be.above(35000);
45     });
46   },
47
48   'default builds': function () {
49     builder(function (err, result) {
50       should.strictEqual(err, null);
51
52       var io = common.execute(result).io
53         , transports = Object.keys(io.Transport)
54         , defaults = Object.keys(builder.transports);
55
56       /* XHR transport is private, but still available */
57       transports.length.should().be.equal(defaults.length + 1);
58
59       defaults.forEach(function (transport) {
60         transports.indexOf(transport).should().be.above(-1);
61       })
62     });
63   },
64
65   'custom build': function () {
66     builder(['websocket'], function (err, result) {
67       should.strictEqual(err, null);
68
69       var io = common.execute(result).io
70         , transports = Object.keys(io.Transport);
71
72       transports.should().have.length(1);
73       transports[0].should().eql('websocket');
74     });
75   },
76
77   'custom code': function () {
78     var custom = 'var hello = "world";';
79     builder({ custom: [custom], minify: false }, function (err, result) {
80       should.strictEqual(err, null);
81
82       result.should().include.string(custom);
83     });
84   },
85
86   'node if': function () {
87     var custom = '// if node \nvar hello = "world";\n'
88       + '// end node\nvar pew = "pew";';
89
90     builder({ custom: [custom], minify: false }, function (err, result) {
91       should.strictEqual(err, null);
92
93       result.should().not.include.string(custom);
94       result.should().not.include.string('// if node');
95       result.should().not.include.string('// end node');
96       result.should().not.include.string('"world"');
97
98       result.should().include.string('var pew = "pew"');
99     });
100   },
101
102   'preserve the encoding during minification': function () {
103     builder(function (err, result) {
104       should.strictEqual(err, null);
105
106       result.should().match(/(\\ufffd)/g);
107     })
108   },
109
110   'globals': function () {
111     builder(function (err, result) {
112       should.strictEqual(err, null);
113
114       var io = common.execute(result)
115         , env = common.env()
116         , allowed = ['io', 'swfobject', 'WEB_SOCKET_DISABLE_AUTO_INITIALIZATION'];
117
118       Array.prototype.push.apply(allowed, Object.keys(env));
119
120       Object.keys(io).forEach(function (global) {
121         var index = allowed.indexOf(global);
122
123         // the global is not allowed!
124         if (!~index) {
125           throw new Error('Global leak: ' + global);
126         }
127       });
128     })
129   }
130
131 };