3 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
11 var builder = require('../../bin/builder')
12 , common = require('./builder.common')
13 , should = require('should');
21 'version number': function () {
22 builder.version.should().match(/([0-9]+)\.([0-9]+)\.([0-9]+)/);
23 builder.version.should().equal(require('../../lib/io').version);
26 'production build LOC': function () {
27 builder(function (err, result) {
28 should.strictEqual(err, null)
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);
37 'development build LOC': function () {
38 builder({ minify: false }, function (err, result) {
39 should.strictEqual(err, null)
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);
48 'default builds': function () {
49 builder(function (err, result) {
50 should.strictEqual(err, null);
52 var io = common.execute(result).io
53 , transports = Object.keys(io.Transport)
54 , defaults = Object.keys(builder.transports);
56 /* XHR transport is private, but still available */
57 transports.length.should().be.equal(defaults.length + 1);
59 defaults.forEach(function (transport) {
60 transports.indexOf(transport).should().be.above(-1);
65 'custom build': function () {
66 builder(['websocket'], function (err, result) {
67 should.strictEqual(err, null);
69 var io = common.execute(result).io
70 , transports = Object.keys(io.Transport);
72 transports.should().have.length(1);
73 transports[0].should().eql('websocket');
77 'custom code': function () {
78 var custom = 'var hello = "world";';
79 builder({ custom: [custom], minify: false }, function (err, result) {
80 should.strictEqual(err, null);
82 result.should().include.string(custom);
86 'node if': function () {
87 var custom = '// if node \nvar hello = "world";\n'
88 + '// end node\nvar pew = "pew";';
90 builder({ custom: [custom], minify: false }, function (err, result) {
91 should.strictEqual(err, null);
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"');
98 result.should().include.string('var pew = "pew"');
102 'preserve the encoding during minification': function () {
103 builder(function (err, result) {
104 should.strictEqual(err, null);
106 result.should().match(/(\\ufffd)/g);
110 'globals': function () {
111 builder(function (err, result) {
112 should.strictEqual(err, null);
114 var io = common.execute(result)
116 , allowed = ['io', 'swfobject', 'WEB_SOCKET_DISABLE_AUTO_INITIALIZATION'];
118 Array.prototype.push.apply(allowed, Object.keys(env));
120 Object.keys(io).forEach(function (global) {
121 var index = allowed.indexOf(global);
123 // the global is not allowed!
125 throw new Error('Global leak: ' + global);