diff --git a/extensions/vscode-notebook-tests/package.json b/extensions/vscode-notebook-tests/package.json index 0a6b5ee625de6e132502481b78d964951bf8ecc7..83f73669e0a977c844ba2bbaf98b6343218b5a5f 100644 --- a/extensions/vscode-notebook-tests/package.json +++ b/extensions/vscode-notebook-tests/package.json @@ -54,6 +54,15 @@ } ] } + ], + "notebookOutputRenderer": [ + { + "viewType": "notebookCoreTestRenderer", + "displayName": "Notebook Core Test Renderer", + "mimeTypes": [ + "text/custom" + ] + } ] } } diff --git a/extensions/vscode-notebook-tests/src/customRenderer.js b/extensions/vscode-notebook-tests/src/customRenderer.js new file mode 100644 index 0000000000000000000000000000000000000000..75e2ec1eb7ad4c42523e90991089f340133af36d --- /dev/null +++ b/extensions/vscode-notebook-tests/src/customRenderer.js @@ -0,0 +1,13 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +const vscode = acquireVsCodeApi(); + +vscode.postMessage({ + type: 'custom_renderer_initialize', + payload: { + firstMessage: true + } +}); diff --git a/extensions/vscode-notebook-tests/src/notebook.test.ts b/extensions/vscode-notebook-tests/src/notebook.test.ts index a54d9121703a464fed2f3f7a5492b0ab4d7aa032..1c296a79e6370151628ccd2faca48fa339f97a00 100644 --- a/extensions/vscode-notebook-tests/src/notebook.test.ts +++ b/extensions/vscode-notebook-tests/src/notebook.test.ts @@ -689,7 +689,7 @@ suite('regression', () => { }); -suite('webview resource uri', () => { +suite('webview', () => { test('asWebviewUri', async function () { const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb')); await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); @@ -698,4 +698,23 @@ suite('webview resource uri', () => { assert.equal(uri.scheme, 'vscode-webview-resource'); await vscode.commands.executeCommand('workbench.action.closeAllEditors'); }); + + test('custom renderer message', async function () { + const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './customRenderer.vsctestnb')); + await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest'); + + const editor = vscode.notebook.activeNotebookEditor; + const promise = new Promise(resolve => { + const messageEmitter = editor?.onDidReceiveMessage(e => { + if (e.type === 'custom_renderer_initialize') { + resolve(); + messageEmitter?.dispose(); + } + }); + }); + + await vscode.commands.executeCommand('notebook.cell.execute'); + await promise; + await vscode.commands.executeCommand('workbench.action.closeAllEditors'); + }); }); diff --git a/extensions/vscode-notebook-tests/src/notebookTestMain.ts b/extensions/vscode-notebook-tests/src/notebookTestMain.ts index 155a8e2c847669b6713831da5dba80e8ba022d11..059f998acae6910fceda65e614945094212d8ee1 100644 --- a/extensions/vscode-notebook-tests/src/notebookTestMain.ts +++ b/extensions/vscode-notebook-tests/src/notebookTestMain.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import * as path from 'path'; import { smokeTestActivate } from './notebookSmokeTestMain'; export function activate(context: vscode.ExtensionContext): any { @@ -66,13 +67,38 @@ export function activate(context: vscode.ExtensionContext): any { _cell = _document.cells[0]; } + if (_document.uri.path.endsWith('customRenderer.vsctestnb')) { + _cell.outputs = [{ + outputKind: vscode.CellOutputKind.Rich, + data: { + 'text/custom': 'test' + } + }]; + + return; + } + _cell.outputs = [{ outputKind: vscode.CellOutputKind.Rich, data: { 'text/plain': ['my output'] } }]; + return; } })); + + const preloadUri = vscode.Uri.file(path.resolve(__dirname, '../src/customRenderer.js')); + context.subscriptions.push(vscode.notebook.registerNotebookOutputRenderer('notebookCoreTestRenderer', { + type: 'display_data', + subTypes: [ + 'text/custom' + ] + }, { + preloads: [preloadUri], + render(_document: vscode.NotebookDocument, _output: vscode.CellDisplayOutput, _mimeType: string): string { + return '
test
'; + } + })); } diff --git a/extensions/vscode-notebook-tests/test/customRenderer.vsctestnb b/extensions/vscode-notebook-tests/test/customRenderer.vsctestnb new file mode 100644 index 0000000000000000000000000000000000000000..a4a092d83492f73541c48127da38563b8fce621d --- /dev/null +++ b/extensions/vscode-notebook-tests/test/customRenderer.vsctestnb @@ -0,0 +1,4 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/