diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/interactiveWindow.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/interactiveWindow.test.ts index 2f648d6df6f..c85fdcb4c81 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/interactiveWindow.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/interactiveWindow.test.ts @@ -30,16 +30,25 @@ async function addCell(code: string, notebook: vscode.NotebookDocument) { const edit = vscode.NotebookEdit.insertCells(notebook.cellCount, [cell]); const workspaceEdit = new vscode.WorkspaceEdit(); workspaceEdit.set(notebook.uri, [edit]); + const event = asPromise(vscode.workspace.onDidChangeNotebookDocument); await vscode.workspace.applyEdit(workspaceEdit); + await event; return notebook.cellAt(notebook.cellCount - 1); } -async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i: number) { +async function addCellAndRun(code: string, notebook: vscode.NotebookDocument) { + const initialCellCount = notebook.cellCount; const cell = await addCell(code, notebook); + const event = asPromise(vscode.workspace.onDidChangeNotebookDocument); - await vscode.commands.executeCommand('notebook.cell.execute', { start: i, end: i + 1 }, notebook.uri); - await event; - assert.strictEqual(cell.outputs.length, 1, 'execute failed'); + await vscode.commands.executeCommand('notebook.cell.execute', { start: initialCellCount, end: initialCellCount + 1 }, notebook.uri); + try { + await event; + } catch (e) { + const result = notebook.cellAt(notebook.cellCount - 1); + assert.fail(`Notebook change event was not triggered after executing newly added cell. Initial Cell count: ${initialCellCount}. Current cell count: ${notebook.cellCount}. execution summary: ${JSON.stringify(result.executionSummary)}`); + } + assert.strictEqual(cell.outputs.length, 1, `Executed cell has no output. Initial Cell count: ${initialCellCount}. Current cell count: ${notebook.cellCount}. execution summary: ${JSON.stringify(cell.executionSummary)}`); return cell; } @@ -86,7 +95,7 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i: // Run and add a bunch of cells for (let i = 0; i < 10; i++) { - await addCellAndRun(`print ${i}`, notebookEditor.notebook, i); + await addCellAndRun(`print ${i}`, notebookEditor.notebook); } // Verify visible range has the last cell @@ -105,7 +114,7 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i: assert.ok(notebookEditor); // Verify the kernel is the secondary one - await addCellAndRun(`print`, notebookEditor.notebook, 0); + await addCellAndRun(`print`, notebookEditor.notebook); assert.strictEqual(secondKernel.associatedNotebooks.has(notebookEditor.notebook.uri.toString()), true, `Secondary kernel was not set as the kernel for the interactive window`);