From 51ae42c1d200dd88726093401b9ab44cf317d671 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Mon, 17 Nov 2014 00:43:13 -0800 Subject: [PATCH] fix tests --- lib/games.js | 1 + lib/test/test-utils.js | 4 ++++ public/hft/0.x.x/scripts/gameclient.js | 2 +- public/hft/0.x.x/scripts/localnetplayer.js | 2 +- public/hft/0.x.x/scripts/netplayer.js | 2 +- server/available-games.js | 2 +- server/hft-server.js | 4 +++- server/hftgame-client.js | 2 +- server/relayserver.js | 1 - 9 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/games.js b/lib/games.js index 173619bc..14bc268e 100644 --- a/lib/games.js +++ b/lib/games.js @@ -159,6 +159,7 @@ var InstalledGamesList = function() { * @param {string} gamePathOrId path to game or gameId */ var remove = function(gamePathOrId, options) { + options = options || {}; try { getInstalledGames(); if (options.bad) { diff --git a/lib/test/test-utils.js b/lib/test/test-utils.js index edd2a08e..03cb6f09 100644 --- a/lib/test/test-utils.js +++ b/lib/test/test-utils.js @@ -82,6 +82,7 @@ var createMockHTTPServer = function() { var createHFTServerWithMocks = function(callback) { + var AvailableGames = require('../../server/available-games.js'); var LocalWebSocketServer = require('../../server/localwebsocketserver') var HFTServer = require('../../server/hft-server'); var RelayServer = require('../../server/relayserver.js'); @@ -115,8 +116,10 @@ var createHFTServerWithMocks = function(callback) { var MockedHFTServer = function(callback) { var httpServer = createMockHTTPServer(); + var gameDB = new AvailableGames(); var relayServer = new RelayServer([httpServer], { WebSocketServer: LocalWebSocketServer, + gameDB: gameDB, }); var hftServer = hftServer = new HFTServer({ port: 0, // should not be used. @@ -124,6 +127,7 @@ var createHFTServerWithMocks = function(callback) { privateServer: true, httpServer: httpServer, relayServer: relayServer, + gameDB: gameDB, }, callback); this.close = function() { diff --git a/public/hft/0.x.x/scripts/gameclient.js b/public/hft/0.x.x/scripts/gameclient.js index 6c378ab6..73ebdcb5 100644 --- a/public/hft/0.x.x/scripts/gameclient.js +++ b/public/hft/0.x.x/scripts/gameclient.js @@ -124,7 +124,7 @@ define(['./virtualsocket'], function(VirtualSocket) { if (fn) { fn.apply(this, args); } else { - console.error("unknown event: " + eventType); + console.error("GameClient: unknown event: " + eventType); } }.bind(this); diff --git a/public/hft/0.x.x/scripts/localnetplayer.js b/public/hft/0.x.x/scripts/localnetplayer.js index 8edd2c68..eb3aa562 100644 --- a/public/hft/0.x.x/scripts/localnetplayer.js +++ b/public/hft/0.x.x/scripts/localnetplayer.js @@ -120,7 +120,7 @@ define(function() { if (fn) { fn.call(this, data); } else { - console.error("Unknown Event: " + eventType); + console.error("LocalNetPlayer: Unknown Event: " + eventType); } }; diff --git a/public/hft/0.x.x/scripts/netplayer.js b/public/hft/0.x.x/scripts/netplayer.js index 415eee60..7faf3b5f 100644 --- a/public/hft/0.x.x/scripts/netplayer.js +++ b/public/hft/0.x.x/scripts/netplayer.js @@ -139,7 +139,7 @@ define(function() { if (fn) { fn.apply(this, args); } else { - console.error("Unknown Event: " + eventType); + console.error("NetPlayer: Unknown Event: " + eventType); } }; diff --git a/server/available-games.js b/server/available-games.js index b06edbb0..671607ec 100644 --- a/server/available-games.js +++ b/server/available-games.js @@ -51,7 +51,7 @@ var AvailableGames = function() { this.on = emitter.on.bind(emitter); this.addListener = this.on; - this.removeListender = emitter.removeListener.bind(emitter); + this.removeListener = emitter.removeListener.bind(emitter); this.reset = gameDB.reset.bind(gameDB); // When getting games only get what's installed diff --git a/server/hft-server.js b/server/hft-server.js index c7a070ef..6487ba54 100644 --- a/server/hft-server.js +++ b/server/hft-server.js @@ -73,6 +73,7 @@ mime.define({'application/javascript': ["js6"]}); * rendezvous server * @property {RelayServer?} relayServer relay server to use. (for testing) * @property {HttpServer?} httpServer http server to use. (for testing) + * @property {GameDB?} gameDB GameDB to use (for testing) * @property {string?} systemName name to use if mulitiple * happyFunTimes servers are running on the same * network. @@ -92,13 +93,14 @@ var HFTServer = function(options, startedCallback) { screenshotCount: 0, baseDir: "public", cwd: process.cwd(), - gameDB: new AvailableGames(), }; Object.keys(options).forEach(function(prop) { g[prop] = options[prop]; }); + g.gameDB = options.gameDB || new AvailableGames(); + var eventEmitter = new events.EventEmitter(); var nonRequire = new NonRequire(); var es6Support = new ES6Support({fileSystem: nonRequire.fileSystem}); diff --git a/server/hftgame-client.js b/server/hftgame-client.js index f44eb0a2..8a8c4369 100644 --- a/server/hftgame-client.js +++ b/server/hftgame-client.js @@ -57,8 +57,8 @@ var HFTGameClient = function(options) { }; var noop = function() { }; - client.addEventListener('hftInfo', noop); + client.addEventListener('connect', noop); this.disconnectGame = function(filter) { return new Promise(function(resolve, reject) { diff --git a/server/relayserver.js b/server/relayserver.js index d0d463a6..7c1d10f0 100644 --- a/server/relayserver.js +++ b/server/relayserver.js @@ -76,7 +76,6 @@ var WSServer = require('./websocketserver'); * @params {RelayServer~Options} options */ var RelayServer = function(servers, options) { - var g_nextSessionId = 0; var g_gameGroups = {}; var g_numGameGroups = 0;