notebook webview test
parent
b3162f52c6
commit
627dd8b0ca
|
@ -54,6 +54,15 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"notebookOutputRenderer": [
|
||||
{
|
||||
"viewType": "notebookCoreTestRenderer",
|
||||
"displayName": "Notebook Core Test Renderer",
|
||||
"mimeTypes": [
|
||||
"text/custom"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
});
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 '<div>test</div>';
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*--------------------------------------------------------------------------------------------*/
|
Loading…
Reference in New Issue