Skip to content

Commit 627dd8b

Browse files
committed
notebook webview test
1 parent b3162f5 commit 627dd8b

5 files changed

Lines changed: 72 additions & 1 deletion

File tree

extensions/vscode-notebook-tests/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
}
5555
]
5656
}
57+
],
58+
"notebookOutputRenderer": [
59+
{
60+
"viewType": "notebookCoreTestRenderer",
61+
"displayName": "Notebook Core Test Renderer",
62+
"mimeTypes": [
63+
"text/custom"
64+
]
65+
}
5766
]
5867
}
5968
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const vscode = acquireVsCodeApi();
7+
8+
vscode.postMessage({
9+
type: 'custom_renderer_initialize',
10+
payload: {
11+
firstMessage: true
12+
}
13+
});

extensions/vscode-notebook-tests/src/notebook.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ suite('regression', () => {
689689

690690
});
691691

692-
suite('webview resource uri', () => {
692+
suite('webview', () => {
693693
test('asWebviewUri', async function () {
694694
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
695695
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -698,4 +698,23 @@ suite('webview resource uri', () => {
698698
assert.equal(uri.scheme, 'vscode-webview-resource');
699699
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
700700
});
701+
702+
test('custom renderer message', async function () {
703+
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './customRenderer.vsctestnb'));
704+
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
705+
706+
const editor = vscode.notebook.activeNotebookEditor;
707+
const promise = new Promise(resolve => {
708+
const messageEmitter = editor?.onDidReceiveMessage(e => {
709+
if (e.type === 'custom_renderer_initialize') {
710+
resolve();
711+
messageEmitter?.dispose();
712+
}
713+
});
714+
});
715+
716+
await vscode.commands.executeCommand('notebook.cell.execute');
717+
await promise;
718+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
719+
});
701720
});

extensions/vscode-notebook-tests/src/notebookTestMain.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import * as path from 'path';
78
import { smokeTestActivate } from './notebookSmokeTestMain';
89

910
export function activate(context: vscode.ExtensionContext): any {
@@ -66,13 +67,38 @@ export function activate(context: vscode.ExtensionContext): any {
6667
_cell = _document.cells[0];
6768
}
6869

70+
if (_document.uri.path.endsWith('customRenderer.vsctestnb')) {
71+
_cell.outputs = [{
72+
outputKind: vscode.CellOutputKind.Rich,
73+
data: {
74+
'text/custom': 'test'
75+
}
76+
}];
77+
78+
return;
79+
}
80+
6981
_cell.outputs = [{
7082
outputKind: vscode.CellOutputKind.Rich,
7183
data: {
7284
'text/plain': ['my output']
7385
}
7486
}];
87+
7588
return;
7689
}
7790
}));
91+
92+
const preloadUri = vscode.Uri.file(path.resolve(__dirname, '../src/customRenderer.js'));
93+
context.subscriptions.push(vscode.notebook.registerNotebookOutputRenderer('notebookCoreTestRenderer', {
94+
type: 'display_data',
95+
subTypes: [
96+
'text/custom'
97+
]
98+
}, {
99+
preloads: [preloadUri],
100+
render(_document: vscode.NotebookDocument, _output: vscode.CellDisplayOutput, _mimeType: string): string {
101+
return '<div>test</div>';
102+
}
103+
}));
78104
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)