From 9699ccb73223d98a6f3f69ba27cb015ec1c46115 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 31 Oct 2022 11:31:01 -0700 Subject: [PATCH] Adopt notebook serializer for test For #160580 --- .../singlefolder-tests/notebook.api.test.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.api.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.api.test.ts index 51b82032c77ab..373321d9bf427 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.api.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.api.test.ts @@ -30,13 +30,15 @@ function sleep(ms: number): Promise { }); } +const notebookType = 'notebookCoreTest'; + export class Kernel { readonly controller: vscode.NotebookController; readonly associatedNotebooks = new Set(); - constructor(id: string, label: string, viewType: string = 'notebookCoreTest') { + constructor(id: string, label: string, viewType: string = notebookType) { this.controller = vscode.notebooks.createNotebookController(id, viewType, label); this.controller.executeHandler = this._execute.bind(this); this.controller.supportsExecutionOrder = true; @@ -75,15 +77,11 @@ function getFocusedCell(editor?: vscode.NotebookEditor) { return editor ? editor.notebook.cellAt(editor.selections[0].start) : undefined; } -const apiTestContentProvider: vscode.NotebookContentProvider = { - openNotebook: async (resource: vscode.Uri): Promise => { - if (/.*empty\-.*\.vsctestnb$/.test(resource.path)) { - return { - metadata: {}, - cells: [] - }; - } - +const apiTestSerializer: vscode.NotebookSerializer = { + serializeNotebook(_data, _token) { + return new Uint8Array(); + }, + deserializeNotebook(_content, _token) { const dto: vscode.NotebookData = { metadata: { custom: { testMetadata: false } }, cells: [ @@ -134,7 +132,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = { }); suiteSetup(function () { - suiteDisposables.push(vscode.workspace.registerNotebookContentProvider('notebookCoreTest', apiTestContentProvider)); + suiteDisposables.push(vscode.workspace.registerNotebookSerializer(notebookType, apiTestSerializer)); }); let defaultKernel: Kernel; @@ -226,7 +224,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = { }); test('#102411 - untitled notebook creation failed', async function () { - await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: 'notebookCoreTest' }); + await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: notebookType }); assert.notStrictEqual(vscode.window.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined'); await closeAllEditors();