builder.test.js 3.4 KB

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