add simple unittest

This commit is contained in:
Benjamin Sergeant
2018-12-29 18:33:15 -08:00
parent 3b67032adb
commit 43cd6d34ca
17 changed files with 15196 additions and 1 deletions

23
test/broadcast-server.js Normal file
View File

@ -0,0 +1,23 @@
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
// Broadcast to all.
wss.broadcast = function broadcast(data) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
};
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(data) {
// Broadcast to everyone else.
wss.clients.forEach(function each(client) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
});
});