MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / createMockKernel

Function createMockKernel

src/kernels/helpers.unit.test.ts:664–700  ·  view source on GitHub ↗
(options: MockKernelOptions)

Source from the content-addressed store, hash-verified

662 }
663
664 function createMockKernel(options: MockKernelOptions) {
665 return {
666 requestExecute: () => {
667 let resolvePromise: (value: any) => void;
668
669 // Create a promise that will be resolved after IOPub messages are dispatched
670 const donePromise = new Promise<any>((resolve) => {
671 resolvePromise = resolve;
672 });
673
674 return {
675 done: donePromise,
676 set onIOPub(cb: (msg: any) => void) {
677 // Invoke IOPub callback synchronously with all messages
678 if (options.messages && options.messages.length > 0) {
679 options.messages.forEach((msg) => {
680 cb({
681 header: { msg_type: msg.msg_type },
682 content: msg.content
683 });
684 });
685 }
686 // Resolve the done promise after messages are dispatched
687 resolvePromise({
688 content:
689 options.status === 'ok'
690 ? { status: 'ok' as const }
691 : {
692 status: 'error' as const,
693 ...options.errorContent
694 }
695 });
696 }
697 };
698 }
699 };
700 }
701
702 test('Returns outputs from kernel execution', async () => {
703 const mockKernel = createMockKernel({

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected