From 627dd8b0ca4042ab7bb1b2d56fd6df10af5d12f9 Mon Sep 17 00:00:00 2001 From: rebornix Date: Wed, 20 May 2020 13:19:16 -0700 Subject: [PATCH] notebook webview test --- extensions/vscode-notebook-tests/package.json | 9 +++++++ .../src/customRenderer.js | 13 ++++++++++ .../src/notebook.test.ts | 21 ++++++++++++++- .../src/notebookTestMain.ts | 26 +++++++++++++++++++ .../test/customRenderer.vsctestnb | 4 +++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 extensions/vscode-notebook-tests/src/customRenderer.js create mode 100644 extensions/vscode-notebook-tests/test/customRenderer.vsctestnb diff --git a/extensions/vscode-notebook-tests/package.json b/extensions/vscode-notebook-tests/package.json index 0a6b5ee625d..83f73669e0a 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 00000000000..75e2ec1eb7a --- /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 a54d9121703..1c296a79e63 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 155a8e2c847..059f998acae 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 00000000000..a4a092d8349 --- /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. + *--------------------------------------------------------------------------------------------*/ -- GitLab