mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
Merge branch 'master' into joh/celldocs
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import { join } from 'path';
|
||||
import { createRandomFile } from './utils';
|
||||
|
||||
export function timeoutAsync(n: number): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
@@ -56,6 +56,42 @@ async function splitEditor() {
|
||||
await once;
|
||||
}
|
||||
|
||||
async function saveFileAndCloseAll(resource: vscode.Uri) {
|
||||
const documentClosed = new Promise((resolve, _reject) => {
|
||||
const d = vscode.notebook.onDidCloseNotebookDocument(e => {
|
||||
if (e.uri.toString() === resource.toString()) {
|
||||
d.dispose();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await documentClosed;
|
||||
}
|
||||
|
||||
async function saveAllFilesAndCloseAll(resource: vscode.Uri) {
|
||||
const documentClosed = new Promise((resolve, _reject) => {
|
||||
const d = vscode.notebook.onDidCloseNotebookDocument(e => {
|
||||
if (e.uri.toString() === resource.toString()) {
|
||||
d.dispose();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await documentClosed;
|
||||
}
|
||||
|
||||
function assertInitalState() {
|
||||
// no-op unless we figure out why some documents are opened after the editor is closed
|
||||
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor, undefined);
|
||||
// assert.equal(vscode.notebook.notebookDocuments.length, 0);
|
||||
// assert.equal(vscode.notebook.visibleNotebookEditors.length, 0);
|
||||
}
|
||||
|
||||
suite('Notebook API tests', () => {
|
||||
// test.only('crash', async function () {
|
||||
// for (let i = 0; i < 200; i++) {
|
||||
@@ -83,7 +119,9 @@ suite('Notebook API tests', () => {
|
||||
// });
|
||||
|
||||
test('document open/close event', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
const firstDocumentOpen = getEventOncePromise(vscode.notebook.onDidOpenNotebookDocument);
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await firstDocumentOpen;
|
||||
@@ -134,7 +172,9 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('shared document in notebook editors', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
let counter = 0;
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
disposables.push(vscode.notebook.onDidOpenNotebookDocument(() => {
|
||||
@@ -155,7 +195,9 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('editor open/close event', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
const firstEditorOpen = getEventOncePromise(vscode.notebook.onDidChangeVisibleNotebookEditors);
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await firstEditorOpen;
|
||||
@@ -166,7 +208,9 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('editor open/close event 2', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
let count = 0;
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
disposables.push(vscode.notebook.onDidChangeVisibleNotebookEditors(() => {
|
||||
@@ -184,7 +228,9 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('editor editing event 2', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
const cellsChangeEvent = getEventOncePromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
|
||||
@@ -256,7 +302,8 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('editor move cell event', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||
@@ -297,7 +344,8 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('notebook editor active/visible', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
const firstEditor = vscode.notebook.activeNotebookEditor;
|
||||
assert.equal(firstEditor?.active, true);
|
||||
@@ -332,7 +380,8 @@ suite('Notebook API tests', () => {
|
||||
});
|
||||
|
||||
test('notebook active editor change', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
const firstEditorOpen = getEventOncePromise(vscode.notebook.onDidChangeActiveNotebookEditor);
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await firstEditorOpen;
|
||||
@@ -341,12 +390,12 @@ suite('Notebook API tests', () => {
|
||||
await vscode.commands.executeCommand('workbench.action.splitEditor');
|
||||
await firstEditorDeactivate;
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
test('edit API', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
const cellsChangeEvent = getEventOncePromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
|
||||
@@ -361,12 +410,12 @@ suite('Notebook API tests', () => {
|
||||
assert.deepEqual(cellChangeEventRet.changes[0].deletedCount, 0);
|
||||
assert.equal(cellChangeEventRet.changes[0].items[0], vscode.notebook.activeNotebookEditor!.document.cells[1]);
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
test('initialzation should not emit cell change events.', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
|
||||
let count = 0;
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
@@ -378,14 +427,15 @@ suite('Notebook API tests', () => {
|
||||
assert.equal(count, 0);
|
||||
|
||||
disposables.forEach(d => d.dispose());
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
});
|
||||
|
||||
suite('notebook workflow', () => {
|
||||
test('notebook open', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
@@ -406,7 +456,8 @@ suite('notebook workflow', () => {
|
||||
});
|
||||
|
||||
test('notebook cell actions', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
@@ -479,7 +530,8 @@ suite('notebook workflow', () => {
|
||||
});
|
||||
|
||||
test('notebook join cells', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
@@ -487,7 +539,9 @@ suite('notebook workflow', () => {
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
const cellsChangeEvent = getEventOncePromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
|
||||
await vscode.commands.executeCommand('notebook.cell.joinAbove');
|
||||
@@ -500,7 +554,8 @@ suite('notebook workflow', () => {
|
||||
});
|
||||
|
||||
test('move cells will not recreate cells in ExtHost', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||
@@ -513,15 +568,14 @@ suite('notebook workflow', () => {
|
||||
|
||||
const newActiveCell = vscode.notebook.activeNotebookEditor!.selection;
|
||||
assert.deepEqual(activeCell, newActiveCell);
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
|
||||
await saveFileAndCloseAll(resource);
|
||||
// TODO@rebornix, there are still some events order issue.
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(newActiveCell!), 2);
|
||||
});
|
||||
|
||||
// test.only('document metadata is respected', async function () {
|
||||
// const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
// const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
@@ -545,7 +599,8 @@ suite('notebook workflow', () => {
|
||||
// });
|
||||
|
||||
test('cell runnable metadata is respected', async () => {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
const editor = vscode.notebook.activeNotebookEditor!;
|
||||
@@ -566,7 +621,8 @@ suite('notebook workflow', () => {
|
||||
});
|
||||
|
||||
test('document runnable metadata is respected', async () => {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
const editor = vscode.notebook.activeNotebookEditor!;
|
||||
@@ -588,7 +644,8 @@ suite('notebook workflow', () => {
|
||||
|
||||
suite('notebook dirty state', () => {
|
||||
test('notebook open', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
@@ -604,25 +661,22 @@ suite('notebook dirty state', () => {
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
|
||||
|
||||
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile');
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(activeCell!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
|
||||
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;');
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
});
|
||||
|
||||
suite('notebook undo redo', () => {
|
||||
test('notebook open', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'test');
|
||||
@@ -640,14 +694,16 @@ suite('notebook undo redo', () => {
|
||||
|
||||
|
||||
// modify the second cell, delete it
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
await vscode.commands.executeCommand('notebook.cell.delete');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
|
||||
|
||||
|
||||
// undo should bring back the deleted cell, and revert to previous content and selection
|
||||
await vscode.commands.executeCommand('notebook.undo');
|
||||
await vscode.commands.executeCommand('undo');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;');
|
||||
@@ -658,12 +714,12 @@ suite('notebook undo redo', () => {
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'test');
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
test.skip('execute and then undo redo', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
const cellsChangeEvent = getEventOncePromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
|
||||
@@ -713,7 +769,7 @@ suite('notebook undo redo', () => {
|
||||
assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 1);
|
||||
|
||||
const cellOutputClear = getEventOncePromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
|
||||
await vscode.commands.executeCommand('notebook.undo');
|
||||
await vscode.commands.executeCommand('undo');
|
||||
const cellOutputsCleardRet = await cellOutputClear;
|
||||
assert.deepEqual(cellOutputsCleardRet, {
|
||||
document: vscode.notebook.activeNotebookEditor!.document,
|
||||
@@ -721,15 +777,14 @@ suite('notebook undo redo', () => {
|
||||
});
|
||||
assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 0);
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('notebook working copy', () => {
|
||||
// test('notebook revert on close', async function () {
|
||||
// const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
// const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
@@ -750,7 +805,7 @@ suite('notebook working copy', () => {
|
||||
// });
|
||||
|
||||
// test('notebook revert', async function () {
|
||||
// const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
// const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
@@ -770,15 +825,18 @@ suite('notebook working copy', () => {
|
||||
// });
|
||||
|
||||
test('multiple tabs: dirty + clean', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
const secondResource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './second.vsctestnb'));
|
||||
const secondResource = await createRandomFile('', undefined, 'second', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
|
||||
@@ -789,20 +847,22 @@ suite('notebook working copy', () => {
|
||||
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 3);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;');
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
test('multiple tabs: two dirty tabs and switching', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
const secondResource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './second.vsctestnb'));
|
||||
const secondResource = await createRandomFile('', undefined, 'second', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', secondResource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
@@ -823,13 +883,15 @@ suite('notebook working copy', () => {
|
||||
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 2);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), '');
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveAllFilesAndCloseAll(secondResource);
|
||||
// await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
});
|
||||
|
||||
test('multiple tabs: different editors with same document', async function () {
|
||||
assertInitalState();
|
||||
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
const firstNotebookEditor = vscode.notebook.activeNotebookEditor;
|
||||
assert.equal(firstNotebookEditor !== undefined, true, 'notebook first');
|
||||
@@ -846,28 +908,31 @@ suite('notebook working copy', () => {
|
||||
assert.equal(firstNotebookEditor?.document, secondNotebookEditor?.document, 'split notebook editors share the same document');
|
||||
assert.notEqual(firstNotebookEditor?.asWebviewUri(vscode.Uri.file('./hello.png')), secondNotebookEditor?.asWebviewUri(vscode.Uri.file('./hello.png')));
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveAllFilesAndCloseAll(resource);
|
||||
|
||||
// await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
});
|
||||
});
|
||||
|
||||
suite('metadata', () => {
|
||||
test('custom metadata should be supported', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123);
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
|
||||
// TODO@rebornix skip as it crashes the process all the time
|
||||
test.skip('custom metadata should be supported', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
test.skip('custom metadata should be supported 2', async function () {
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.metadata.custom!['testMetadata'] as boolean, false);
|
||||
@@ -880,27 +945,29 @@ suite('metadata', () => {
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
|
||||
// assert.equal(activeCell?.metadata.custom!['testCellMetadata'] as number, 123);
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
});
|
||||
|
||||
suite('regression', () => {
|
||||
test('microsoft/vscode-github-issue-notebooks#26. Insert template cell in the new empty document', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'empty', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
|
||||
await vscode.commands.executeCommand('workbench.action.files.saveAll');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
await saveFileAndCloseAll(resource);
|
||||
});
|
||||
|
||||
test('#97830, #97764. Support switch to other editor types', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'empty', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), 'var abc = 0;');
|
||||
@@ -909,33 +976,37 @@ suite('regression', () => {
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
|
||||
assert.equal(vscode.window.activeTextEditor?.document.uri.path, resource.path);
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
});
|
||||
|
||||
// open text editor, pin, and then open a notebook
|
||||
test('#96105 - dirty editors', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'empty', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
|
||||
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(resource, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
// now it's dirty, open the resource with notebook editor should open a new one
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
assert.notEqual(vscode.notebook.activeNotebookEditor, undefined, 'notebook first');
|
||||
assert.notEqual(vscode.window.activeTextEditor, undefined);
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor');
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
});
|
||||
|
||||
test('#102411 - untitled notebook creation failed', async function () {
|
||||
assertInitalState();
|
||||
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: 'notebookCoreTest' });
|
||||
assert.notEqual(vscode.notebook.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined');
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
});
|
||||
|
||||
test('#102423 - copy/paste shares the same text buffer', async function () {
|
||||
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
assertInitalState();
|
||||
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
let activeCell = vscode.notebook.activeNotebookEditor!.selection;
|
||||
@@ -947,10 +1018,14 @@ suite('regression', () => {
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
|
||||
assert.equal(activeCell?.document.getText(), 'test');
|
||||
|
||||
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(vscode.notebook.activeNotebookEditor!.selection!.uri, new vscode.Position(0, 0), 'var abc = 0;');
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
|
||||
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2);
|
||||
assert.notEqual(vscode.notebook.activeNotebookEditor!.document.cells[0].document.getText(), vscode.notebook.activeNotebookEditor!.document.cells[1].document.getText());
|
||||
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -961,11 +1036,11 @@ suite('webview', () => {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
|
||||
// const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
|
||||
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
// assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
|
||||
// const uri = vscode.notebook.activeNotebookEditor!.asWebviewUri(vscode.Uri.file('./hello.png'));
|
||||
// assert.equal(uri.scheme, 'vscode-resource');
|
||||
// assert.equal(uri.scheme, 'vscode-webview-resource');
|
||||
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
// });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user