(options?: CreateMockCellOptions)
| 79 | * @returns A mock NotebookCell |
| 80 | */ |
| 81 | export function createMockCell(options?: CreateMockCellOptions): NotebookCell { |
| 82 | const opts = options ?? {}; |
| 83 | const { |
| 84 | kind = NotebookCellKind.Code, |
| 85 | languageId = 'python', |
| 86 | text = '', |
| 87 | outputs = [], |
| 88 | notebookType = 'deepnote', |
| 89 | notebookUri = Uri.file('/test/notebook.deepnote'), |
| 90 | index = 0 |
| 91 | } = opts; |
| 92 | |
| 93 | // Preserve explicit undefined for metadata fields |
| 94 | const metadata = Object.prototype.hasOwnProperty.call(opts, 'metadata') ? opts.metadata : {}; |
| 95 | const notebookMetadata = Object.prototype.hasOwnProperty.call(opts, 'notebookMetadata') |
| 96 | ? opts.notebookMetadata |
| 97 | : {}; |
| 98 | |
| 99 | const notebook = createMockNotebook({ |
| 100 | notebookType, |
| 101 | uri: notebookUri, |
| 102 | metadata: notebookMetadata |
| 103 | }); |
| 104 | |
| 105 | const cellPath = `${notebookUri.path}#cell${index}`; |
| 106 | |
| 107 | const document = { |
| 108 | uri: Uri.file(cellPath), |
| 109 | fileName: cellPath, |
| 110 | isUntitled: false, |
| 111 | languageId, |
| 112 | version: 1, |
| 113 | isDirty: false, |
| 114 | isClosed: false, |
| 115 | getText: () => text, |
| 116 | save: async () => true, |
| 117 | eol: 1, |
| 118 | lineCount: 1, |
| 119 | lineAt: () => ({ text: '' }) as unknown, |
| 120 | offsetAt: () => 0, |
| 121 | positionAt: () => ({}) as unknown, |
| 122 | validateRange: () => ({}) as unknown, |
| 123 | validatePosition: () => ({}) as unknown, |
| 124 | getWordRangeAtPosition: () => undefined |
| 125 | } as unknown as TextDocument; |
| 126 | |
| 127 | return { |
| 128 | index, |
| 129 | notebook, |
| 130 | kind, |
| 131 | document, |
| 132 | metadata, |
| 133 | outputs, |
| 134 | executionSummary: undefined |
| 135 | } as unknown as NotebookCell; |
| 136 | } |
no test coverage detected