mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 09:38:38 +01:00
make output on cancel/interrupt unit tests instead of integration tests, https://github.com/microsoft/vscode/issues/125665
This commit is contained in:
@@ -566,90 +566,6 @@ suite('Notebook API tests', function () {
|
||||
});
|
||||
});
|
||||
|
||||
test('set outputs on cancel', async () => {
|
||||
|
||||
const cancelableKernel = new class extends Kernel {
|
||||
|
||||
constructor() {
|
||||
super('cancelableKernel', 'Notebook Cancelable Test Kernel');
|
||||
}
|
||||
|
||||
override async _execute(cells: vscode.NotebookCell[]) {
|
||||
for (const cell of cells) {
|
||||
const task = this.controller.createNotebookCellExecution(cell);
|
||||
task.start();
|
||||
task.token.onCancellationRequested(async () => {
|
||||
await task.replaceOutput([new vscode.NotebookCellOutput([
|
||||
vscode.NotebookCellOutputItem.text('Canceled', 'text/plain')
|
||||
])]);
|
||||
task.end(undefined);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
const editor = await vscode.window.showNotebookDocument(notebook);
|
||||
const cell = editor.document.cellAt(0);
|
||||
|
||||
await withEvent<vscode.NotebookCellOutputsChangeEvent>(vscode.notebooks.onDidChangeCellOutputs, async (event) => {
|
||||
await assertKernel(cancelableKernel, notebook);
|
||||
assert.ok(editor === vscode.window.activeNotebookEditor);
|
||||
await vscode.commands.executeCommand('notebook.cell.execute');
|
||||
await vscode.commands.executeCommand('notebook.cell.cancelExecution');
|
||||
await event;
|
||||
assert.strictEqual(cell.outputs.length, 1, 'should execute'); // runnable, it worked
|
||||
assert.strictEqual(cell.outputs[0].items.length, 1);
|
||||
assert.strictEqual(cell.outputs[0].items[0].mime, 'text/plain');
|
||||
assert.deepStrictEqual(new TextDecoder().decode(cell.outputs[0].items[0].data), 'Canceled');
|
||||
});
|
||||
|
||||
cancelableKernel.controller.dispose();
|
||||
});
|
||||
|
||||
test('set outputs on interrupt', async () => {
|
||||
const interruptableKernel = new class extends Kernel {
|
||||
|
||||
constructor() {
|
||||
super('interruptableKernel', 'Notebook Interruptable Test Kernel');
|
||||
this.controller.interruptHandler = this.interrupt.bind(this);
|
||||
}
|
||||
|
||||
private _task: vscode.NotebookCellExecution | undefined;
|
||||
|
||||
override async _execute(cells: vscode.NotebookCell[]) {
|
||||
this._task = this.controller.createNotebookCellExecution(cells[0]);
|
||||
this._task.start();
|
||||
}
|
||||
|
||||
async interrupt() {
|
||||
await this._task!.replaceOutput([new vscode.NotebookCellOutput([
|
||||
vscode.NotebookCellOutputItem.text('Interrupted', 'text/plain')
|
||||
])]);
|
||||
this._task!.end(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
const editor = await vscode.window.showNotebookDocument(notebook);
|
||||
const cell = editor.document.cellAt(0);
|
||||
|
||||
await withEvent<vscode.NotebookCellOutputsChangeEvent>(vscode.notebooks.onDidChangeCellOutputs, async (event) => {
|
||||
await assertKernel(interruptableKernel, notebook);
|
||||
assert.ok(editor === vscode.window.activeNotebookEditor);
|
||||
await vscode.commands.executeCommand('notebook.cell.execute');
|
||||
await vscode.commands.executeCommand('notebook.cell.cancelExecution');
|
||||
await event;
|
||||
assert.strictEqual(cell.outputs.length, 1, 'should execute'); // runnable, it worked
|
||||
assert.strictEqual(cell.outputs[0].items.length, 1);
|
||||
assert.strictEqual(cell.outputs[0].items[0].mime, 'text/plain');
|
||||
assert.deepStrictEqual(new TextDecoder().decode(cell.outputs[0].items[0].data), 'Interrupted');
|
||||
});
|
||||
|
||||
interruptableKernel.controller.dispose();
|
||||
});
|
||||
|
||||
test('onDidChangeCellExecutionState is fired', async () => {
|
||||
const resource = await createRandomNotebookFile();
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
Reference in New Issue
Block a user