Skip to content

Commit 57d1262

Browse files
committed
wait for document close when finishing a test.
1 parent 4a1a4ae commit 57d1262

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

extensions/vscode-notebook-tests/src/notebook.test.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ async function splitEditor() {
5656
await once;
5757
}
5858

59+
async function saveFileAndCloseAll(resource: vscode.Uri) {
60+
const documentClosed = new Promise((resolve, _reject) => {
61+
const d = vscode.notebook.onDidCloseNotebookDocument(e => {
62+
if (e.uri.toString() === resource.toString()) {
63+
d.dispose();
64+
resolve();
65+
}
66+
});
67+
});
68+
await vscode.commands.executeCommand('workbench.action.files.save');
69+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
70+
await documentClosed;
71+
}
72+
5973
suite('Notebook API tests', () => {
6074
// test.only('crash', async function () {
6175
// for (let i = 0; i < 200; i++) {
@@ -574,8 +588,7 @@ suite('notebook dirty state', () => {
574588
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection);
575589
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;');
576590

577-
await vscode.commands.executeCommand('workbench.action.files.save');
578-
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
591+
await saveFileAndCloseAll(resource);
579592
});
580593
});
581594

@@ -619,8 +632,7 @@ suite('notebook undo redo', () => {
619632
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
620633
// assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'test');
621634

622-
await vscode.commands.executeCommand('workbench.action.files.save');
623-
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
635+
await saveFileAndCloseAll(resource);
624636
});
625637

626638
test.skip('execute and then undo redo', async function () {
@@ -682,8 +694,7 @@ suite('notebook undo redo', () => {
682694
});
683695
assert.equal(cellOutputsAddedRet.cells[0].outputs.length, 0);
684696

685-
await vscode.commands.executeCommand('workbench.action.files.save');
686-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
697+
await saveFileAndCloseAll(resource);
687698
});
688699

689700
});
@@ -752,8 +763,7 @@ suite('notebook working copy', () => {
752763
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 3);
753764
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), 'var abc = 0;');
754765

755-
await vscode.commands.executeCommand('workbench.action.files.save');
756-
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
766+
await saveFileAndCloseAll(resource);
757767
});
758768

759769
test('multiple tabs: two dirty tabs and switching', async function () {
@@ -825,8 +835,7 @@ suite('metadata', () => {
825835
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.metadata.custom!['testCellMetadata'] as number, 123);
826836
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
827837

828-
await vscode.commands.executeCommand('workbench.action.files.saveAll');
829-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
838+
await saveFileAndCloseAll(resource);
830839
});
831840

832841

@@ -845,8 +854,7 @@ suite('metadata', () => {
845854
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
846855
// assert.equal(activeCell?.metadata.custom!['testCellMetadata'] as number, 123);
847856

848-
await vscode.commands.executeCommand('workbench.action.files.saveAll');
849-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
857+
await saveFileAndCloseAll(resource);
850858
});
851859
});
852860

@@ -857,8 +865,7 @@ suite('regression', () => {
857865
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
858866
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.document.getText(), '');
859867
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
860-
await vscode.commands.executeCommand('workbench.action.files.saveAll');
861-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
868+
await saveFileAndCloseAll(resource);
862869
});
863870

864871
test('#97830, #97764. Support switch to other editor types', async function () {

0 commit comments

Comments
 (0)