Skip to content

Commit 72e7d2d

Browse files
committed
DEV test update
1 parent cde3361 commit 72e7d2d

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/__tests__/__snapshots__/server.toolsHost.test.ts.snap

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,54 @@ exports[`requestShutdown should send shutdown:ack and exit, with valid request 1
346346
],
347347
]
348348
`;
349+
350+
exports[`setHandlers should set up message handlers and attempt handle requests, hello 1`] = `
351+
[
352+
[
353+
{
354+
"id": "test-id",
355+
"t": "hello:ack",
356+
},
357+
],
358+
]
359+
`;
360+
361+
exports[`setHandlers should set up message handlers and attempt handle requests, invoke 1`] = `
362+
[
363+
[
364+
{
365+
"error": {
366+
"message": "Unknown toolId",
367+
},
368+
"id": "test-id",
369+
"ok": false,
370+
"t": "invoke:result",
371+
},
372+
],
373+
]
374+
`;
375+
376+
exports[`setHandlers should set up message handlers and attempt handle requests, load 1`] = `
377+
[
378+
[
379+
{
380+
"errors": [],
381+
"id": "test-id",
382+
"t": "load:ack",
383+
"warnings": [],
384+
},
385+
],
386+
]
387+
`;
388+
389+
exports[`setHandlers should set up message handlers and attempt handle requests, manifest:get 1`] = `
390+
[
391+
[
392+
{
393+
"id": "test-id",
394+
"t": "manifest:result",
395+
"tools": [],
396+
},
397+
],
398+
]
399+
`;

src/__tests__/server.toolsHost.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,47 @@ describe('requestFallback', () => {
390390
}).not.toThrow();
391391
});
392392
});
393+
394+
describe('setHandlers', () => {
395+
let mockOn: jest.Mock;
396+
let mockSend: jest.Mock;
397+
398+
beforeEach(() => {
399+
mockSend = jest.fn();
400+
mockOn = jest.fn();
401+
402+
process.on = mockOn;
403+
process.send = mockSend;
404+
});
405+
406+
afterEach(() => {
407+
jest.clearAllMocks();
408+
delete (process as any).send;
409+
});
410+
411+
it.each([
412+
{
413+
description: 'hello',
414+
request: { t: 'hello', id: 'test-id' }
415+
},
416+
{
417+
description: 'load',
418+
request: { t: 'load', id: 'test-id' }
419+
},
420+
{
421+
description: 'manifest:get',
422+
request: { t: 'manifest:get', id: 'test-id' }
423+
},
424+
{
425+
description: 'invoke',
426+
request: { t: 'invoke', id: 'test-id' }
427+
}
428+
])('should set up message handlers and attempt handle requests, $description', async ({ request }) => {
429+
const handler = setHandlers();
430+
431+
await handler(request as any);
432+
433+
expect(mockOn).toHaveBeenCalledWith('message', expect.any(Function));
434+
expect(mockSend.mock.calls).toMatchSnapshot();
435+
});
436+
});

0 commit comments

Comments
 (0)