|
5 | 5 |
|
6 | 6 | import * as assert from 'assert';
|
7 | 7 | import 'mocha';
|
8 |
| -import { TextDecoder } from 'util'; |
| 8 | +import { TextDecoder, TextEncoder } from 'util'; |
9 | 9 | import * as vscode from 'vscode';
|
10 | 10 | import { asPromise, assertNoRpc, closeAllEditors, createRandomFile, disposeAll, revertAllDirty, saveAllEditors } from '../utils';
|
11 | 11 |
|
@@ -986,3 +986,57 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
|
986 | 986 | assert.strictEqual(getFocusedCell(editor)?.document.languageId, 'typescript');
|
987 | 987 | });
|
988 | 988 | });
|
| 989 | + |
| 990 | +suite('Notebook & LiveShare', function () { |
| 991 | + |
| 992 | + const suiteDisposables: vscode.Disposable[] = []; |
| 993 | + const notebookType = 'vsls-testing'; |
| 994 | + |
| 995 | + suiteTeardown(() => { |
| 996 | + vscode.Disposable.from(...suiteDisposables).dispose(); |
| 997 | + }); |
| 998 | + |
| 999 | + suiteSetup(function () { |
| 1000 | + |
| 1001 | + suiteDisposables.push(vscode.workspace.registerNotebookSerializer(notebookType, new class implements vscode.NotebookSerializer { |
| 1002 | + deserializeNotebook(content: Uint8Array, _token: vscode.CancellationToken): vscode.NotebookData | Thenable<vscode.NotebookData> { |
| 1003 | + const value = new TextDecoder().decode(content); |
| 1004 | + return new vscode.NotebookData([new vscode.NotebookCellData(vscode.NotebookCellKind.Code, value, 'fooLang')]); |
| 1005 | + } |
| 1006 | + serializeNotebook(data: vscode.NotebookData, _token: vscode.CancellationToken): Uint8Array | Thenable<Uint8Array> { |
| 1007 | + return new TextEncoder().encode(data.cells[0].value); |
| 1008 | + } |
| 1009 | + }, {}, { |
| 1010 | + displayName: 'LS', |
| 1011 | + filenamePattern: ['*'], |
| 1012 | + })); |
| 1013 | + }); |
| 1014 | + |
| 1015 | + test('command: vscode.resolveNotebookContentProviders', async function () { |
| 1016 | + |
| 1017 | + type Info = { viewType: string; displayName: string; filenamePattern: string[] }; |
| 1018 | + |
| 1019 | + const info = await vscode.commands.executeCommand<Info[]>('vscode.resolveNotebookContentProviders'); |
| 1020 | + assert.strictEqual(Array.isArray(info), true); |
| 1021 | + |
| 1022 | + const item = info.find(item => item.viewType === notebookType); |
| 1023 | + assert.ok(item); |
| 1024 | + assert.strictEqual(item?.viewType, notebookType); |
| 1025 | + }); |
| 1026 | + |
| 1027 | + test('command: vscode.executeDataToNotebook', async function () { |
| 1028 | + const value = 'dataToNotebook'; |
| 1029 | + const data = await vscode.commands.executeCommand<vscode.NotebookData>('vscode.executeDataToNotebook', notebookType, new TextEncoder().encode(value)); |
| 1030 | + assert.ok(data instanceof vscode.NotebookData); |
| 1031 | + assert.strictEqual(data.cells.length, 1); |
| 1032 | + assert.strictEqual(data.cells[0].value, value); |
| 1033 | + }); |
| 1034 | + |
| 1035 | + test('command: vscode.executeNotebookToData', async function () { |
| 1036 | + const value = 'notebookToData'; |
| 1037 | + const notebook = new vscode.NotebookData([new vscode.NotebookCellData(vscode.NotebookCellKind.Code, value, 'fooLang')]); |
| 1038 | + const data = await vscode.commands.executeCommand<Uint8Array>('vscode.executeNotebookToData', notebookType, notebook); |
| 1039 | + assert.ok(data instanceof Uint8Array); |
| 1040 | + assert.deepStrictEqual(new TextDecoder().decode(data), value); |
| 1041 | + }); |
| 1042 | +}); |
0 commit comments