Skip to content

Commit e83010a

Browse files
committed
silent fail when the documents events are wrong
1 parent baeae3e commit e83010a

2 files changed

Lines changed: 129 additions & 10 deletions

File tree

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

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ async function saveFileAndCloseAll(resource: vscode.Uri) {
7070
await documentClosed;
7171
}
7272

73+
async function saveAllFilesAndCloseAll(resource: vscode.Uri) {
74+
const documentClosed = new Promise((resolve, _reject) => {
75+
const d = vscode.notebook.onDidCloseNotebookDocument(e => {
76+
if (e.uri.toString() === resource.toString()) {
77+
d.dispose();
78+
resolve();
79+
}
80+
});
81+
});
82+
await vscode.commands.executeCommand('workbench.action.files.saveAll');
83+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
84+
await documentClosed;
85+
}
86+
87+
function assertInitalState() {
88+
if (vscode.notebook.activeNotebookEditor !== undefined) {
89+
return false;
90+
}
91+
92+
if (vscode.notebook.notebookDocuments.length !== 0) {
93+
return false;
94+
}
95+
96+
if (vscode.notebook.visibleNotebookEditors.length !== 0) {
97+
return false;
98+
}
99+
100+
return true;
101+
}
102+
73103
suite('Notebook API tests', () => {
74104
// test.only('crash', async function () {
75105
// for (let i = 0; i < 200; i++) {
@@ -97,6 +127,9 @@ suite('Notebook API tests', () => {
97127
// });
98128

99129
test('document open/close event', async function () {
130+
if (!assertInitalState()) {
131+
return;
132+
}
100133
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
101134
const firstDocumentOpen = getEventOncePromise(vscode.notebook.onDidOpenNotebookDocument);
102135
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -108,6 +141,9 @@ suite('Notebook API tests', () => {
108141
});
109142

110143
test('shared document in notebook editors', async function () {
144+
if (!assertInitalState()) {
145+
return;
146+
}
111147
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
112148
let counter = 0;
113149
const disposables: vscode.Disposable[] = [];
@@ -129,6 +165,9 @@ suite('Notebook API tests', () => {
129165
});
130166

131167
test('editor open/close event', async function () {
168+
if (!assertInitalState()) {
169+
return;
170+
}
132171
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
133172
const firstEditorOpen = getEventOncePromise(vscode.notebook.onDidChangeVisibleNotebookEditors);
134173
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -140,6 +179,9 @@ suite('Notebook API tests', () => {
140179
});
141180

142181
test('editor open/close event 2', async function () {
182+
if (!assertInitalState()) {
183+
return;
184+
}
143185
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
144186
let count = 0;
145187
const disposables: vscode.Disposable[] = [];
@@ -158,6 +200,9 @@ suite('Notebook API tests', () => {
158200
});
159201

160202
test('editor editing event 2', async function () {
203+
if (!assertInitalState()) {
204+
return;
205+
}
161206
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
162207
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
163208

@@ -230,6 +275,9 @@ suite('Notebook API tests', () => {
230275
});
231276

232277
test('editor move cell event', async function () {
278+
if (!assertInitalState()) {
279+
return;
280+
}
233281
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
234282
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
235283
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@@ -271,6 +319,9 @@ suite('Notebook API tests', () => {
271319
});
272320

273321
test('notebook editor active/visible', async function () {
322+
if (!assertInitalState()) {
323+
return;
324+
}
274325
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
275326
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
276327
const firstEditor = vscode.notebook.activeNotebookEditor;
@@ -306,6 +357,9 @@ suite('Notebook API tests', () => {
306357
});
307358

308359
test('notebook active editor change', async function () {
360+
if (!assertInitalState()) {
361+
return;
362+
}
309363
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
310364
const firstEditorOpen = getEventOncePromise(vscode.notebook.onDidChangeActiveNotebookEditor);
311365
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -315,11 +369,13 @@ suite('Notebook API tests', () => {
315369
await vscode.commands.executeCommand('workbench.action.splitEditor');
316370
await firstEditorDeactivate;
317371

318-
await vscode.commands.executeCommand('workbench.action.files.save');
319-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
372+
await saveFileAndCloseAll(resource);
320373
});
321374

322375
test('edit API', async function () {
376+
if (!assertInitalState()) {
377+
return;
378+
}
323379
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
324380
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
325381

@@ -339,6 +395,9 @@ suite('Notebook API tests', () => {
339395
});
340396

341397
test('initialzation should not emit cell change events.', async function () {
398+
if (!assertInitalState()) {
399+
return;
400+
}
342401
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
343402

344403
let count = 0;
@@ -358,6 +417,9 @@ suite('Notebook API tests', () => {
358417

359418
suite('notebook workflow', () => {
360419
test('notebook open', async function () {
420+
if (!assertInitalState()) {
421+
return;
422+
}
361423
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
362424
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
363425
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -379,6 +441,9 @@ suite('notebook workflow', () => {
379441
});
380442

381443
test('notebook cell actions', async function () {
444+
if (!assertInitalState()) {
445+
return;
446+
}
382447
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
383448
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
384449
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -452,6 +517,9 @@ suite('notebook workflow', () => {
452517
});
453518

454519
test('notebook join cells', async function () {
520+
if (!assertInitalState()) {
521+
return;
522+
}
455523
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
456524
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
457525
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -475,6 +543,9 @@ suite('notebook workflow', () => {
475543
});
476544

477545
test('move cells will not recreate cells in ExtHost', async function () {
546+
if (!assertInitalState()) {
547+
return;
548+
}
478549
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
479550
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
480551
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@@ -519,6 +590,9 @@ suite('notebook workflow', () => {
519590
// });
520591

521592
test('cell runnable metadata is respected', async () => {
593+
if (!assertInitalState()) {
594+
return;
595+
}
522596
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
523597
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
524598
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -540,6 +614,9 @@ suite('notebook workflow', () => {
540614
});
541615

542616
test('document runnable metadata is respected', async () => {
617+
if (!assertInitalState()) {
618+
return;
619+
}
543620
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
544621
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
545622
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -562,6 +639,9 @@ suite('notebook workflow', () => {
562639

563640
suite('notebook dirty state', () => {
564641
test('notebook open', async function () {
642+
if (!assertInitalState()) {
643+
return;
644+
}
565645
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
566646
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
567647
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -592,6 +672,9 @@ suite('notebook dirty state', () => {
592672

593673
suite('notebook undo redo', () => {
594674
test('notebook open', async function () {
675+
if (!assertInitalState()) {
676+
return;
677+
}
595678
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
596679
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
597680
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -634,6 +717,9 @@ suite('notebook undo redo', () => {
634717
});
635718

636719
test.skip('execute and then undo redo', async function () {
720+
if (!assertInitalState()) {
721+
return;
722+
}
637723
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
638724
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
639725

@@ -740,6 +826,9 @@ suite('notebook working copy', () => {
740826
// });
741827

742828
test('multiple tabs: dirty + clean', async function () {
829+
if (!assertInitalState()) {
830+
return;
831+
}
743832
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
744833
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
745834
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@@ -765,6 +854,9 @@ suite('notebook working copy', () => {
765854
});
766855

767856
test('multiple tabs: two dirty tabs and switching', async function () {
857+
if (!assertInitalState()) {
858+
return;
859+
}
768860
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
769861
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
770862
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@@ -796,11 +888,15 @@ suite('notebook working copy', () => {
796888
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells.length, 2);
797889
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.document.getText(), '');
798890

799-
await vscode.commands.executeCommand('workbench.action.files.saveAll');
800-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
891+
await saveAllFilesAndCloseAll(secondResource);
892+
// await vscode.commands.executeCommand('workbench.action.files.saveAll');
893+
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
801894
});
802895

803896
test('multiple tabs: different editors with same document', async function () {
897+
if (!assertInitalState()) {
898+
return;
899+
}
804900

805901
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
806902
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -819,13 +915,18 @@ suite('notebook working copy', () => {
819915
assert.equal(firstNotebookEditor?.document, secondNotebookEditor?.document, 'split notebook editors share the same document');
820916
assert.notEqual(firstNotebookEditor?.asWebviewUri(vscode.Uri.file('./hello.png')), secondNotebookEditor?.asWebviewUri(vscode.Uri.file('./hello.png')));
821917

822-
await vscode.commands.executeCommand('workbench.action.files.saveAll');
823-
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
918+
await saveAllFilesAndCloseAll(resource);
919+
920+
// await vscode.commands.executeCommand('workbench.action.files.saveAll');
921+
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
824922
});
825923
});
826924

827925
suite('metadata', () => {
828926
test('custom metadata should be supported', async function () {
927+
if (!assertInitalState()) {
928+
return;
929+
}
829930
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
830931
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
831932
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -838,7 +939,10 @@ suite('metadata', () => {
838939

839940

840941
// TODO@rebornix skip as it crashes the process all the time
841-
test.skip('custom metadata should be supported', async function () {
942+
test.skip('custom metadata should be supported 2', async function () {
943+
if (!assertInitalState()) {
944+
return;
945+
}
842946
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
843947
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
844948
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -858,6 +962,9 @@ suite('metadata', () => {
858962

859963
suite('regression', () => {
860964
test('microsoft/vscode-github-issue-notebooks#26. Insert template cell in the new empty document', async function () {
965+
if (!assertInitalState()) {
966+
return;
967+
}
861968
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
862969
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
863970
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
@@ -867,6 +974,9 @@ suite('regression', () => {
867974
});
868975

869976
test('#97830, #97764. Support switch to other editor types', async function () {
977+
if (!assertInitalState()) {
978+
return;
979+
}
870980
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
871981
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
872982
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
@@ -886,6 +996,9 @@ suite('regression', () => {
886996

887997
// open text editor, pin, and then open a notebook
888998
test('#96105 - dirty editors', async function () {
999+
if (!assertInitalState()) {
1000+
return;
1001+
}
8891002
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './empty.vsctestnb'));
8901003
await vscode.commands.executeCommand('vscode.openWith', resource, 'default');
8911004
const edit = new vscode.WorkspaceEdit();
@@ -901,13 +1014,19 @@ suite('regression', () => {
9011014
});
9021015

9031016
test('#102411 - untitled notebook creation failed', async function () {
1017+
if (!assertInitalState()) {
1018+
return;
1019+
}
9041020
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: 'notebookCoreTest' });
9051021
assert.notEqual(vscode.notebook.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined');
9061022

9071023
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
9081024
});
9091025

9101026
test('#102423 - copy/paste shares the same text buffer', async function () {
1027+
if (!assertInitalState()) {
1028+
return;
1029+
}
9111030
const resource = vscode.Uri.file(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
9121031
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
9131032

scripts/test-integration.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ if "%INTEGRATION_TEST_ELECTRON_PATH%"=="" (
4444

4545
:: Tests in the extension host
4646

47-
call "%INTEGRATION_TEST_ELECTRON_PATH%" %~dp0\..\extensions\vscode-notebook-tests\test --enable-proposed-api=vscode.vscode-notebook-tests --extensionDevelopmentPath=%~dp0\..\extensions\vscode-notebook-tests --extensionTestsPath=%~dp0\..\extensions\vscode-notebook-tests\out --disable-telemetry --crash-reporter-directory=%VSCODECRASHDIR% --no-cached-data --disable-updates --disable-extensions --user-data-dir=%VSCODEUSERDATADIR%
48-
if %errorlevel% neq 0 exit /b %errorlevel%
49-
5047
call "%INTEGRATION_TEST_ELECTRON_PATH%" %~dp0\..\extensions\vscode-api-tests\testWorkspace --enable-proposed-api=vscode.vscode-api-tests --extensionDevelopmentPath=%~dp0\..\extensions\vscode-api-tests --extensionTestsPath=%~dp0\..\extensions\vscode-api-tests\out\singlefolder-tests --disable-telemetry --crash-reporter-directory=%VSCODECRASHDIR% --no-cached-data --disable-updates --disable-extensions --user-data-dir=%VSCODEUSERDATADIR%
5148
if %errorlevel% neq 0 exit /b %errorlevel%
5249

@@ -65,6 +62,9 @@ if %errorlevel% neq 0 exit /b %errorlevel%
6562
call "%INTEGRATION_TEST_ELECTRON_PATH%" $%~dp0\..\extensions\emmet\out\test\test-fixtures --extensionDevelopmentPath=%~dp0\..\extensions\emmet --extensionTestsPath=%~dp0\..\extensions\emmet\out\test --disable-telemetry --crash-reporter-directory=%VSCODECRASHDIR% --no-cached-data --disable-updates --disable-extensions --user-data-dir=%VSCODEUSERDATADIR% .
6663
if %errorlevel% neq 0 exit /b %errorlevel%
6764

65+
call "%INTEGRATION_TEST_ELECTRON_PATH%" %~dp0\..\extensions\vscode-notebook-tests\test --enable-proposed-api=vscode.vscode-notebook-tests --extensionDevelopmentPath=%~dp0\..\extensions\vscode-notebook-tests --extensionTestsPath=%~dp0\..\extensions\vscode-notebook-tests\out --disable-telemetry --crash-reporter-directory=%VSCODECRASHDIR% --no-cached-data --disable-updates --disable-extensions --user-data-dir=%VSCODEUSERDATADIR%
66+
if %errorlevel% neq 0 exit /b %errorlevel%
67+
6868
for /f "delims=" %%i in ('node -p "require('fs').realpathSync.native(require('os').tmpdir())"') do set TEMPDIR=%%i
6969
set GITWORKSPACE=%TEMPDIR%\git-%RANDOM%
7070
mkdir %GITWORKSPACE%

0 commit comments

Comments
 (0)