test: allow 3rd party test socket handling

This commit is contained in:
cha0s 2024-02-15 03:24:38 -06:00
parent 0942827ed4
commit 6a5de499df
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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;
}
});
});