-
Notifications
You must be signed in to change notification settings - Fork 934
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds onCommand support to plugins. (#84)
- Loading branch information
Showing
3 changed files
with
60 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import test from 'ava' | ||
import { createClient } from '../src' | ||
import getFreePort from './_get-free-port' | ||
import socketClient from 'socket.io-client' | ||
import socketServer from 'socket.io' | ||
|
||
test.cb('plugins support send', t => { | ||
const mockType = 'type' | ||
const mockPayload = 'payload' | ||
|
||
// odd way to hold on to the plugin's send function | ||
let capturedSend | ||
|
||
// the plugin to extract the send function | ||
const plugin = config => { | ||
capturedSend = config.send | ||
return {} | ||
} | ||
|
||
getFreePort(port => { | ||
// the server waits for the command | ||
socketServer(port) | ||
.on('connection', socket => { | ||
// send through the one we recieved in the plugin | ||
capturedSend(mockType, mockPayload) | ||
|
||
// fires the server receives a command | ||
socket.on('command', ({type, payload}) => { | ||
t.is(type, mockType) | ||
t.deepEqual(payload, mockPayload) | ||
t.end() | ||
}) | ||
}) | ||
|
||
// create the client, add the plugin, and connect | ||
createClient({ io: socketClient, port: port }) | ||
.use(plugin) | ||
.connect() | ||
}) | ||
}) |