aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node
diff options
context:
space:
mode:
Diffstat (limited to 'signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node')
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.common.js102
-rw-r--r--signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.test.js131
2 files changed, 233 insertions, 0 deletions
diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.common.js b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.common.js
new file mode 100644
index 0000000..fa8d46e
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.common.js
@@ -0,0 +1,102 @@
+
+/*!
+ * socket.io-node
+ * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+var vm = require('vm')
+ , should = require('should');
+
+/**
+ * Generates evn variables for the vm so we can `emulate` a browser.
+ * @returns {Object} evn variables
+ */
+
+exports.env = function env () {
+ var details = {
+ location: {
+ port: 8080
+ , host: 'www.example.org'
+ , hostname: 'www.example.org'
+ , href: 'http://www.example.org/example/'
+ , pathname: '/example/'
+ , protocol: 'http:'
+ , search: ''
+ , hash: ''
+ }
+ , console: {
+ log: function(){},
+ info: function(){},
+ warn: function(){},
+ error: function(){}
+ }
+ , navigator: {
+ userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit'
+ + '/534.27 (KHTML, like Gecko) Chrome/12.0.716.0 Safari/534.27'
+ , appName: 'socket.io'
+ , platform: process.platform
+ , appVersion: process.version
+ , }
+ , name: 'socket.io'
+ , innerWidth: 1024
+ , innerHeight: 768
+ , length: 1
+ , outerWidth: 1024
+ , outerHeight: 768
+ , pageXOffset: 0
+ , pageYOffset: 0
+ , screenX: 0
+ , screenY: 0
+ , screenLeft: 0
+ , screenTop: 0
+ , scrollX: 0
+ , scrollY: 0
+ , scrollTop: 0
+ , scrollLeft: 0
+ , screen: {
+ width: 0
+ , height: 0
+ }
+ };
+
+ // circular references
+ details.window = details.self = details.contentWindow = details;
+
+ // callable methods
+ details.Image = details.scrollTo = details.scrollBy = details.scroll =
+ details.resizeTo = details.resizeBy = details.prompt = details.print =
+ details.open = details.moveTo = details.moveBy = details.focus =
+ details.createPopup = details.confirm = details.close = details.blur =
+ details.alert = details.clearTimeout = details.clearInterval =
+ details.setInterval = details.setTimeout = details.XMLHttpRequest =
+ details.getComputedStyle = details.trigger = details.dispatchEvent =
+ details.removeEventListener = details.addEventListener = function(){};
+
+ // frames
+ details.frames = [details];
+
+ // document
+ details.document = details;
+ details.document.domain = details.location.href;
+
+ return details;
+};
+
+/**
+ * Executes a script in a browser like env and returns
+ * the result
+ *
+ * @param {String} contents The script content
+ * @returns {Object} The evaluated script.
+ */
+
+exports.execute = function execute (contents) {
+ var env = exports.env()
+ , script = vm.createScript(contents);
+
+ // run the script with `browser like` globals
+ script.runInNewContext(env);
+
+ return env;
+};
diff --git a/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.test.js b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.test.js
new file mode 100644
index 0000000..989e2bc
--- /dev/null
+++ b/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.test.js
@@ -0,0 +1,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);
+ }
+ });
+ })
+ }
+
+};