Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt notebook serializer for test #165078

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ function sleep(ms: number): Promise<void> {
});
}

const notebookType = 'notebookCoreTest';

export class Kernel {

readonly controller: vscode.NotebookController;

readonly associatedNotebooks = new Set<string>();

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;
Expand Down Expand Up @@ -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<vscode.NotebookData> => {
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: [
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down