remove unreached code.

This commit is contained in:
rebornix 2021-02-17 11:43:40 -08:00
parent 8cec47ff4a
commit 0354f334ed

View file

@ -6,7 +6,7 @@
import 'mocha';
import * as assert from 'assert';
import * as vscode from 'vscode';
import { createRandomFile, asPromise, disposeAll, closeAllEditors, revertAllDirty } from '../utils';
import { createRandomFile, asPromise, disposeAll, closeAllEditors, revertAllDirty, saveAllEditors } from '../utils';
// Since `workbench.action.splitEditor` command does await properly
// Notebook editor/document events are not guaranteed to be sent to the ext host when promise resolves
@ -27,7 +27,7 @@ async function saveFileAndCloseAll(resource: vscode.Uri) {
});
});
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
await documentClosed;
}
@ -44,7 +44,7 @@ async function saveAllFilesAndCloseAll(resource: vscode.Uri | undefined) {
});
});
await vscode.commands.executeCommand('workbench.action.files.saveAll');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
await documentClosed;
}
@ -65,14 +65,6 @@ async function withEvent<T>(event: vscode.Event<T>, callback: (e: Promise<T>) =>
await callback(e);
}
function assertInitalState() {
// no-op unless we figure out why some documents are opened after the editor is closed
// assert.strictEqual(vscode.window.activeNotebookEditor, undefined);
// assert.strictEqual(vscode.notebook.notebookDocuments.length, 0);
// assert.strictEqual(vscode.notebook.visibleNotebookEditors.length, 0);
}
suite('Notebook API tests', function () {
const disposables: vscode.Disposable[] = [];
@ -209,48 +201,8 @@ suite('Notebook API tests', function () {
}));
});
// test.only('crash', async function () {
// for (let i = 0; i < 200; i++) {
// let resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor');
// resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// await vscode.commands.executeCommand('workbench.action.revertAndCloseActiveEditor');
// }
// });
// test.only('crash', async function () {
// for (let i = 0; i < 200; i++) {
// let resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// await vscode.commands.executeCommand('workbench.action.files.save');
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// await vscode.commands.executeCommand('workbench.action.files.save');
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// }
// });
test('document open/close event', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
const firstDocumentOpen = asPromise(vscode.notebook.onDidOpenNotebookDocument);
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await firstDocumentOpen;
const firstDocumentClose = asPromise(vscode.notebook.onDidCloseNotebookDocument);
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await firstDocumentClose;
});
test('shared document in notebook editors', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
const resource = await createRandomFile(undefined, undefined, '.vsctestnb');
let counter = 0;
const disposables: vscode.Disposable[] = [];
disposables.push(vscode.notebook.onDidOpenNotebookDocument(() => {
@ -264,28 +216,24 @@ suite('Notebook API tests', function () {
await splitEditor();
assert.strictEqual(counter, 1);
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
assert.strictEqual(counter, 0);
disposables.forEach(d => d.dispose());
});
test('editor open/close event', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
const firstEditorOpen = asPromise(vscode.window.onDidChangeVisibleNotebookEditors);
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await firstEditorOpen;
const firstEditorClose = asPromise(vscode.window.onDidChangeVisibleNotebookEditors);
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
await firstEditorClose;
});
test('editor open/close event 2', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
let count = 0;
const disposables: vscode.Disposable[] = [];
@ -299,13 +247,11 @@ suite('Notebook API tests', function () {
await splitEditor();
assert.strictEqual(count, 2);
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
assert.strictEqual(count, 0);
});
test('editor editing event 2', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -373,12 +319,10 @@ suite('Notebook API tests', function () {
// language: 'markdown'
// });
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await saveAllFilesAndCloseAll(undefined);
});
test('editor move cell event', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@ -408,19 +352,16 @@ suite('Notebook API tests', function () {
]
});
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await saveAllEditors();
await closeAllEditors();
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
const firstEditor = vscode.window.activeNotebookEditor;
assert.strictEqual(firstEditor?.document.cells.length, 1);
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await saveAllFilesAndCloseAll(undefined);
});
test('notebook editor active/visible', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
const firstEditor = vscode.window.activeNotebookEditor;
@ -449,12 +390,10 @@ suite('Notebook API tests', function () {
assert.strictEqual(vscode.window.visibleNotebookEditors.length, 2);
assert.strictEqual(secondEditor && vscode.window.visibleNotebookEditors.indexOf(secondEditor) >= 0, true);
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await saveAllFilesAndCloseAll(undefined);
});
test('notebook active editor change', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
const firstEditorOpen = asPromise(vscode.window.onDidChangeActiveNotebookEditor);
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -468,7 +407,6 @@ suite('Notebook API tests', function () {
});
test('change cell language', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -492,7 +430,6 @@ suite('Notebook API tests', function () {
});
test('edit API (replaceCells)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -513,7 +450,6 @@ suite('Notebook API tests', function () {
});
test('edit API (replaceOutput, USE NotebookCellOutput-type)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -542,7 +478,6 @@ suite('Notebook API tests', function () {
});
test('edit API (replaceOutput)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -564,7 +499,6 @@ suite('Notebook API tests', function () {
});
test('edit API (replaceOutput, event)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -589,8 +523,6 @@ suite('Notebook API tests', function () {
});
test('edit API (replaceMetadata)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -608,8 +540,6 @@ suite('Notebook API tests', function () {
});
test('edit API (replaceMetadata, event)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -629,7 +559,6 @@ suite('Notebook API tests', function () {
});
test('edit API batch edits', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -648,7 +577,6 @@ suite('Notebook API tests', function () {
});
test('edit API batch edits undo/redo', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -675,7 +603,6 @@ suite('Notebook API tests', function () {
});
test('initialzation should not emit cell change events.', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
let count = 0;
@ -696,7 +623,6 @@ suite('Notebook API tests', function () {
// suite('notebook workflow', () => {
test('notebook open', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -718,7 +644,6 @@ suite('Notebook API tests', function () {
});
test('notebook cell actions', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -792,7 +717,6 @@ suite('Notebook API tests', function () {
});
test('notebook join cells', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -816,7 +740,6 @@ suite('Notebook API tests', function () {
});
test('move cells will not recreate cells in ExtHost', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@ -832,36 +755,10 @@ suite('Notebook API tests', function () {
assert.deepStrictEqual(activeCell, newActiveCell);
await saveFileAndCloseAll(resource);
// TODO@rebornix, there are still some events order issue.
// assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells.indexOf(newActiveCell!), 2);
});
// test.only('document metadata is respected', async function () {
// const resource = await createRandomFile('', undefined, '.vsctestnb');
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
// const editor = vscode.window.activeNotebookEditor!;
// assert.strictEqual(editor.document.cells.length, 1);
// editor.document.metadata.editable = false;
// await editor.edit(builder => builder.delete(0));
// assert.strictEqual(editor.document.cells.length, 1, 'should not delete cell'); // Not editable, no effect
// await editor.edit(builder => builder.insert(0, 'test', 'python', vscode.CellKind.Code, [], undefined));
// assert.strictEqual(editor.document.cells.length, 1, 'should not insert cell'); // Not editable, no effect
// editor.document.metadata.editable = true;
// await editor.edit(builder => builder.delete(0));
// assert.strictEqual(editor.document.cells.length, 0, 'should delete cell'); // Editable, it worked
// await editor.edit(builder => builder.insert(0, 'test', 'python', vscode.CellKind.Code, [], undefined));
// assert.strictEqual(editor.document.cells.length, 1, 'should insert cell'); // Editable, it worked
// // await vscode.commands.executeCommand('workbench.action.files.save');
// await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
// });
test('cell runnable metadata is respected', async () => {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -890,7 +787,6 @@ suite('Notebook API tests', function () {
});
test('document runnable metadata is respected', async () => {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -918,14 +814,12 @@ suite('Notebook API tests', function () {
assert.strictEqual(cell.outputs.length, 1, 'should execute'); // runnable, it worked
});
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await saveAllFilesAndCloseAll(undefined);
});
// TODO@rebornix this is wrong, `await vscode.commands.executeCommand('notebook.execute');` doesn't wait until the workspace edit is applied
test.skip('cell execute command takes arguments', async () => {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -935,12 +829,10 @@ suite('Notebook API tests', function () {
await vscode.commands.executeCommand('notebook.execute');
assert.strictEqual(cell.outputs.length, 0, 'should not execute'); // not runnable, didn't work
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await saveAllFilesAndCloseAll(undefined);
});
test('cell execute command takes arguments 2', async () => {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -974,14 +866,10 @@ suite('Notebook API tests', function () {
assert.strictEqual(vscode.window.activeNotebookEditor?.document.uri.fsPath, secondResource.fsPath);
});
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await saveAllFilesAndCloseAll(undefined);
});
test('document execute command takes arguments', async () => {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -1014,14 +902,10 @@ suite('Notebook API tests', function () {
assert.strictEqual(vscode.window.activeNotebookEditor?.document.uri.fsPath, secondResource.fsPath);
});
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await saveAllFilesAndCloseAll(undefined);
});
test('cell execute and select kernel', async () => {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -1049,14 +933,12 @@ suite('Notebook API tests', function () {
'my second output'
]);
await vscode.commands.executeCommand('workbench.action.files.save');
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
await saveAllFilesAndCloseAll(undefined);
});
// });
// suite('notebook dirty state', () => {
test('notebook open', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -1090,7 +972,6 @@ suite('Notebook API tests', function () {
// suite('notebook undo redo', () => {
test('notebook open', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -1132,115 +1013,7 @@ suite('Notebook API tests', function () {
await saveFileAndCloseAll(resource);
});
// test.skip('execute and then undo redo', async function () {
// assertInitalState();
// const resource = await createRandomFile('', undefined, '.vsctestnb');
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// const cellsChangeEvent = getEventOncePromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
// const cellChangeEventRet = await cellsChangeEvent;
// assert.strictEqual(cellChangeEventRet.document, vscode.window.activeNotebookEditor?.document);
// assert.strictEqual(cellChangeEventRet.changes.length, 1);
// assert.deepStrictEqual(cellChangeEventRet.changes[0], {
// start: 1,
// deletedCount: 0,
// deletedItems: [],
// items: [
// vscode.window.activeNotebookEditor!.document.cells[1]
// ]
// });
// const secondCell = vscode.window.activeNotebookEditor!.document.cells[1];
// const moveCellEvent = getEventOncePromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
// await vscode.commands.executeCommand('notebook.cell.moveUp');
// const moveCellEventRet = await moveCellEvent;
// assert.deepStrictEqual(moveCellEventRet, {
// document: vscode.window.activeNotebookEditor!.document,
// changes: [
// {
// start: 1,
// deletedCount: 1,
// deletedItems: [secondCell],
// items: []
// },
// {
// start: 0,
// deletedCount: 0,
// deletedItems: [],
// items: [vscode.window.activeNotebookEditor?.document.cells[0]]
// }
// ]
// });
// const cellOutputChange = getEventOncePromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
// await vscode.commands.executeCommand('notebook.cell.execute');
// const cellOutputsAddedRet = await cellOutputChange;
// assert.deepStrictEqual(cellOutputsAddedRet, {
// document: vscode.window.activeNotebookEditor!.document,
// cells: [vscode.window.activeNotebookEditor!.document.cells[0]]
// });
// assert.strictEqual(cellOutputsAddedRet.cells[0].outputs.length, 1);
// const cellOutputClear = getEventOncePromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
// await vscode.commands.executeCommand('undo');
// const cellOutputsCleardRet = await cellOutputClear;
// assert.deepStrictEqual(cellOutputsCleardRet, {
// document: vscode.window.activeNotebookEditor!.document,
// cells: [vscode.window.activeNotebookEditor!.document.cells[0]]
// });
// assert.strictEqual(cellOutputsAddedRet.cells[0].outputs.length, 0);
// await saveFileAndCloseAll(resource);
// });
// });
// suite('notebook working copy', () => {
// test('notebook revert on close', async function () {
// const resource = await createRandomFile('', undefined, '.vsctestnb');
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
// assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), '');
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
// await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
// // close active editor from command will revert the file
// await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true);
// assert.strictEqual(vscode.window.activeNotebookEditor?.selection !== undefined, true);
// assert.deepStrictEqual(vscode.window.activeNotebookEditor?.document.cells[0], vscode.window.activeNotebookEditor?.selection);
// assert.strictEqual(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'test');
// await vscode.commands.executeCommand('workbench.action.files.save');
// await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
// });
// test('notebook revert', async function () {
// const resource = await createRandomFile('', undefined, '.vsctestnb');
// await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
// assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), '');
// await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
// await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
// await vscode.commands.executeCommand('workbench.action.files.revert');
// assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true);
// assert.strictEqual(vscode.window.activeNotebookEditor?.selection !== undefined, true);
// assert.deepStrictEqual(vscode.window.activeNotebookEditor?.document.cells[0], vscode.window.activeNotebookEditor?.selection);
// assert.deepStrictEqual(vscode.window.activeNotebookEditor?.document.cells.length, 1);
// assert.strictEqual(vscode.window.activeNotebookEditor?.selection?.document.getText(), 'test');
// await vscode.commands.executeCommand('workbench.action.files.saveAll');
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// });
test('multiple tabs: dirty + clean', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@ -1266,7 +1039,6 @@ suite('Notebook API tests', function () {
});
test('multiple tabs: two dirty tabs and switching', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@ -1299,13 +1071,9 @@ suite('Notebook API tests', function () {
assert.strictEqual(vscode.window.activeNotebookEditor?.selection?.document.getText(), '');
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 = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
const firstNotebookEditor = vscode.window.activeNotebookEditor;
@ -1321,18 +1089,11 @@ suite('Notebook API tests', function () {
assert.notEqual(firstNotebookEditor, secondNotebookEditor);
assert.strictEqual(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 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 () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -1346,7 +1107,6 @@ suite('Notebook API tests', function () {
// TODO@rebornix skip as it crashes the process all the time
test.skip('custom metadata should be supported 2', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
@ -1362,20 +1122,9 @@ suite('Notebook API tests', function () {
await saveFileAndCloseAll(resource);
});
// });
// suite('regression', () => {
// test('microsoft/vscode-github-issue-notebooks#26. Insert template cell in the new empty document', async function () {
// assertInitalState();
// await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { "viewType": "notebookCoreTest" });
// assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
// assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.document.getText(), '');
// assert.strictEqual(vscode.window.activeNotebookEditor!.selection?.language, 'typescript');
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// });
test('#106657. Opening a notebook from markers view is broken ', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -1393,7 +1142,6 @@ suite('Notebook API tests', function () {
});
test.skip('Cannot open notebook from cell-uri with vscode.open-command', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -1411,7 +1159,6 @@ suite('Notebook API tests', function () {
});
test('#97830, #97764. Support switch to other editor types', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@ -1429,12 +1176,11 @@ suite('Notebook API tests', function () {
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
assert.strictEqual(vscode.window.activeTextEditor?.document.uri.path, resource.path);
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
});
// open text editor, pin, and then open a notebook
test('#96105 - dirty editors', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
const edit = new vscode.WorkspaceEdit();
@ -1446,19 +1192,17 @@ suite('Notebook API tests', function () {
assert.notEqual(vscode.window.activeNotebookEditor, undefined, 'notebook first');
// assert.notEqual(vscode.window.activeTextEditor, undefined);
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
});
test('#102411 - untitled notebook creation failed', async function () {
assertInitalState();
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: 'notebookCoreTest' });
assert.notEqual(vscode.window.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined');
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
});
test('#102423 - copy/paste shares the same text buffer', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -1478,11 +1222,10 @@ suite('Notebook API tests', function () {
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cells.length, 2);
assert.notEqual(vscode.window.activeNotebookEditor!.document.cells[0].document.getText(), vscode.window.activeNotebookEditor!.document.cells[1].document.getText());
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await closeAllEditors();
});
test('#116598, output items change event.', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -1510,7 +1253,6 @@ suite('Notebook API tests', function () {
});
test('#115855 onDidSaveNotebookDocument', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -1533,7 +1275,6 @@ suite('Notebook API tests', function () {
test('#116808, active kernel should not be undefined', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@ -1560,7 +1301,7 @@ suite('Notebook API tests', function () {
// assert.strictEqual(vscode.window.activeNotebookEditor !== undefined, true, 'notebook first');
// const uri = vscode.window.activeNotebookEditor!.asWebviewUri(vscode.Uri.file('./hello.png'));
// assert.strictEqual(uri.scheme, 'vscode-webview-resource');
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// await closeAllEditors();
// });
@ -1585,6 +1326,6 @@ suite('Notebook API tests', function () {
// await vscode.commands.executeCommand('notebook.cell.execute');
// await promise;
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// await closeAllEditors();
// });
});