Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Commit

Permalink
Update package scripts, logging; Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcgidw committed Apr 11, 2020
1 parent b1f579f commit e0f2185
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: npm run start-only
web: npm run start
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"clean": "rm -rf dist/ src/public/js/*.min.* src/public/style/*.bundle.*",
"test": "mocha --exit --require @babel/register",
"build": "npm run build-p && npm run build-s",
"start": "npm run build-s && npm run start-only",
"start-only": "node ./dist/server/server.js",
"start": "node ./dist/server/server.js",
"build-p": "webpack --env.production --output-path-info --display-modules",
"watch-p": "webpack --env.development -w --debug --output-path-info --display-modules",
"build-s": "babel -D src/server -d dist/server && babel -D src/common -d dist/common"
Expand Down
15 changes: 12 additions & 3 deletions src/server/game-error.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import debugLog from './debug-log';

class GameError {
constructor(message, clientMessage) {
constructor(message, clientMessage, debugOnly = false) {
this.name = GameError.name;
this.message = message;
this.clientMessage = clientMessage || message;
console.log('GameError triggered: ' + this.toString());

if (debugOnly) {
debugLog('GameError triggered: ' + this.toString());
} else {
console.log('GameError triggered: ' + this.toString());
}
}

static get name() {
return 'GameError';
}

toString() {
return this.message;
}
}
export default GameError;
export default GameError;
4 changes: 3 additions & 1 deletion src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const port = process.env.PORT || 3000;
const io = SocketIO(httpServer);

async function startServer() {
handleSockets(io); // socket.io app logic
const lobby = handleSockets(io); // socket.io app logic

app.use(compress()); // gzip responses

Expand All @@ -26,6 +26,8 @@ async function startServer() {
httpServer.listen(port, function() {
console.log(`httpServer listening on port ${port}`);
});

return lobby;
}

export default startServer();
3 changes: 2 additions & 1 deletion src/server/socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function handleSockets(io) {
});
});
});
return Lobby;
}

const MessageHandlers = {
Expand Down Expand Up @@ -228,7 +229,7 @@ const GamePrecond = {
},
roomIsNotFull(room) {
if (room.isFull()) {
throw new GameError(`Room ${room.roomCode} is full`, 'This room is full');
throw new GameError(`Room ${room.roomCode} is full`, 'This room is full', true);
}
},
lobbyIsNotFull() {
Expand Down
14 changes: 8 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import io from 'socket.io-client';
import MESSAGE from '../src/common/message';
import A from 'async';
import GAME_PHASE from '../src/common/game-phase';
import serverStart from '../src/server/server.js';

describe('Test Suite', function() {
let sock1, sock2, sock3;

beforeEach(function(done) {
import('../src/server/server.js')
.then(function() {
serverStart
.then(function(lobby) {
sock1 = io('http://localhost:3000');
sock2 = io('http://localhost:3000');
sock3 = io('http://localhost:3000');
Expand All @@ -28,7 +29,9 @@ describe('Test Suite', function() {

A.parallel(
[connectSocketFn(sock1), connectSocketFn(sock2), connectSocketFn(sock3)],
() => { done(); }
() => {
done();
}
);
})
.catch(function(e) {
Expand All @@ -38,8 +41,7 @@ describe('Test Suite', function() {

afterEach(function(done) {
[sock1, sock2, sock3].forEach(function(s) {
if(s.connected) {
debugger;
if (s.connected) {
s.disconnect();
console.log('force disconnect');
}
Expand Down Expand Up @@ -190,4 +192,4 @@ describe('Test Suite', function() {
done();
});
});
});
});
8 changes: 4 additions & 4 deletions todo
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
rejoin game after leaving
quick-join via url
redis store
see room code in game
quick-join via url

rules option in-game, make sure resuming works after updates to game state
validate against incompatible browsers or devices
redis store

more setup options
l10n support
more tests
more setup options
rules option in-game, make sure resuming works after updates to game state
vue-router
voting system
colorblind aids

0 comments on commit e0f2185

Please sign in to comment.