test: allow 3rd party test socket handling
This commit is contained in:
parent
0942827ed4
commit
6a5de499df
|
@ -8,6 +8,25 @@ export const hooks = {
|
|||
something: '...',
|
||||
}),
|
||||
|
||||
/**
|
||||
* Respond to server test socket actions.
|
||||
*
|
||||
* @param {Object} action The action.
|
||||
* @param {SocketWrapper} socket The socket.
|
||||
*/
|
||||
'@flecks/server.test.socket': (action, socket) => {
|
||||
const {meta, payload, type} = action;
|
||||
switch (type) {
|
||||
case 'my.custom.action':
|
||||
socket.write(JSON.stringify({
|
||||
meta,
|
||||
payload: 'my-test-response',
|
||||
}));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Define sequential actions to run when the server comes up.
|
||||
* @invoke SequentialAsync
|
||||
|
|
|
@ -19,7 +19,8 @@ export const hook = (flecks) => {
|
|||
flecks.server.socket = socket;
|
||||
socket.on('connect', () => {
|
||||
socket.on('data', (data) => {
|
||||
const {meta, payload, type} = JSON.parse(data);
|
||||
const action = JSON.parse(data);
|
||||
const {meta, payload, type} = action;
|
||||
switch (type) {
|
||||
case 'config.get':
|
||||
socket.write(JSON.stringify({
|
||||
|
@ -32,6 +33,8 @@ export const hook = (flecks) => {
|
|||
process.exit(payload);
|
||||
break;
|
||||
default:
|
||||
flecks.invoke('@flecks/server.test.socket', action, socket);
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user