Skip to content
Browse files

[refactor tests] Finished refactoring tests to support `ws*-to-ws*` t…

…ests based on CLI arguments
  • Loading branch information...
1 parent 828dbeb commit 7e854d778b89201f7cb933e8bbda66316b98b0b4 @indexzero indexzero committed Jul 22, 2012
Showing with 39 additions and 16 deletions.
  1. +1 −1 package.json
  2. +22 −4 test/helpers/ws.js
  3. +13 −8 test/macros/ws.js
  4. +1 −1 test/ws/routing-table-test.js
  5. +1 −1 test/ws/socket.io-test.js
  6. +1 −1 test/ws/ws-test.js
View
2 package.json
@@ -34,7 +34,7 @@
"node-http-proxy": "./bin/node-http-proxy"
},
"scripts": {
- "test": "npm run-script test-http && npm run-script test-https && npm run-script test-core",
+ "test": "npm run-script test-http && npm run-script test-https",
"test-http": "vows --spec && vows --spec --target=https",
"test-https": "vows --spec --proxy=https && vows --spec --proxy=https --target=https",
"test-core": "test/core/run"
View
26 test/helpers/ws.js
@@ -7,9 +7,12 @@
*/
var assert = require('assert'),
+ https = require('https'),
async = require('async'),
io = require('socket.io'),
ws = require('ws'),
+ helpers = require('./index'),
+ protocols = helpers.protocols,
http = require('./http');
//
@@ -62,7 +65,9 @@ exports.createServer = function (options, callback) {
// will expect `options.input` and then send `options.output`.
//
exports.createSocketIoServer = function (options, callback) {
- var server = io.listen(options.port, callback);
+ var server = protocols.target === 'https'
+ ? io.listen(options.port, helpers.https, callback)
+ : io.listen(options.port, callback);
server.sockets.on('connection', function (socket) {
socket.on('incoming', function (data) {
@@ -83,9 +88,22 @@ exports.createSocketIoServer = function (options, callback) {
// will expect `options.input` and then send `options.output`.
//
exports.createWsServer = function (options, callback) {
- var server = new ws.Server({ port: options.port }, callback);
-
- server.on('connection', function (socket) {
+ var server,
+ wss;
+
+ if (protocols.target === 'https') {
+ server = https.createServer(helpers.https, function (req, res) {
+ req.writeHead(200);
+ req.end();
+ }).listen(options.port, callback);
+
+ wss = new ws.Server({ server: server });
+ }
+ else {
+ wss = new ws.Server({ port: options.port }, callback);
+ }
+
+ wss.on('connection', function (socket) {
socket.on('message', function (data) {
assert.equal(data, options.input);
socket.send(options.output);
View
21 test/macros/ws.js
@@ -69,11 +69,13 @@ exports.assertProxied = function (options) {
var ports = options.ports || helpers.nextPortPair,
input = options.input || 'hello world to ' + ports.target,
output = options.output || 'hello world from ' + ports.target,
- protocol = options.protocol || 'http';
+ protocol = helpers.protocols.proxy;
- if (options.raw && !options.protocol) {
- protocol = 'ws';
- }
+ if (options.raw) {
+ protocol = helpers.protocols.proxy === 'https'
+ ? 'wss'
+ : 'ws';
+ }
return {
topic: function () {
@@ -89,6 +91,7 @@ exports.assertProxied = function (options) {
port: ports.proxy,
proxy: {
target: {
+ https: helpers.protocols.target === 'https',
host: '127.0.0.1',
port: ports.target
}
@@ -131,13 +134,15 @@ exports.assertProxiedToRoutes = function (options, nested) {
// Parse locations from routes for making assertion requests.
//
var locations = helpers.http.parseRoutes(options),
- protocol = options.protocol || 'http',
+ protocol = helpers.protocols.proxy,
port = helpers.nextPort,
context,
proxy;
-
- if (options.raw && !options.protocol) {
- protocol = 'ws';
+
+ if (options.raw) {
+ protocol = helpers.protocols.proxy === 'https'
+ ? 'wss'
+ : 'ws';
}
if (options.filename) {
View
2 test/ws/routing-table-test.js
@@ -10,7 +10,7 @@ var vows = require('vows'),
macros = require('../macros'),
helpers = require('../helpers/index');
-vows.describe('node-http-proxy/ws').addBatch({
+vows.describe(helpers.describe('routing-proxy', 'ws')).addBatch({
"With a valid target server": {
"and no latency": {
"using ws": macros.ws.assertProxied(),
View
2 test/ws/socket.io-test.js
@@ -10,7 +10,7 @@ var vows = require('vows'),
macros = require('../macros'),
helpers = require('../helpers/index');
-vows.describe('node-http-proxy/ws/socket.io').addBatch({
+vows.describe(helpers.describe('socket.io', 'ws')).addBatch({
"With a valid target server": {
"and no latency": macros.ws.assertProxied(),
// "and latency": macros.ws.assertProxied({
View
2 test/ws/ws-test.js
@@ -10,7 +10,7 @@ var vows = require('vows'),
macros = require('../macros'),
helpers = require('../helpers/index');
-vows.describe('node-http-proxy/ws/WebSocket').addBatch({
+vows.describe(helpers.describe('websocket', 'ws')).addBatch({
"With a valid target server": {
"and no latency": macros.ws.assertProxied({
raw: true

0 comments on commit 7e854d7

Please sign in to comment.
Something went wrong with that request. Please try again.