Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should set the cell prompt properly while executing', async () => {
const widget = new CodeCell({ model, rendermime, contentFactory });
widget.initializeState();
widget.model.value.text = 'foo';
const future1 = CodeCell.execute(widget, session);
expect(widget.promptNode.textContent).toEqual('[*]:');
const future2 = CodeCell.execute(widget, session);
expect(widget.promptNode.textContent).toEqual('[*]:');
await expect(future1).rejects.toThrow('Canceled');
expect(widget.promptNode.textContent).toEqual('[*]:');
let msg = await future2;
expect(msg).not.toBeUndefined;
// The `if` is a Typescript type guard so that msg.content works below.
if (msg) {
expect(widget.promptNode.textContent).toEqual(
`[${msg.content.execution_count}]:`
);
}
});
});
it('should set the cell prompt properly while executing', async () => {
const widget = new CodeCell({ model, rendermime, contentFactory });
widget.initializeState();
widget.model.value.text = 'foo';
const future1 = CodeCell.execute(widget, session);
expect(widget.promptNode.textContent).toEqual('[*]:');
const future2 = CodeCell.execute(widget, session);
expect(widget.promptNode.textContent).toEqual('[*]:');
await expect(future1).rejects.toThrow('Canceled');
expect(widget.promptNode.textContent).toEqual('[*]:');
let msg = await future2;
expect(msg).not.toBeUndefined;
// The `if` is a Typescript type guard so that msg.content works below.
if (msg) {
expect(widget.promptNode.textContent).toEqual(
`[${msg.content.execution_count}]:`
);
}
});
});
it('should fulfill a promise if there is no code to execute', async () => {
const widget = new CodeCell({ model, rendermime, contentFactory });
widget.initializeState();
try {
await CodeCell.execute(widget, session);
} catch (error) {
throw error;
}
});
cell.setPrompt('');
}
});
}
cell.model.contentChanged.disconnect(this.update, this);
this.update();
this._executed.emit(new Date());
};
let onFailure = () => {
if (this.isDisposed) {
return;
}
cell.model.contentChanged.disconnect(this.update, this);
this.update();
};
return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
}
function runCell(
notebook: Notebook,
cell: Cell,
session?: IClientSession
): Promise {
switch (cell.model.type) {
case 'markdown':
(cell as MarkdownCell).rendered = true;
cell.inputHidden = false;
executed.emit({ notebook, cell });
break;
case 'code':
if (session) {
return CodeCell.execute(cell as CodeCell, session, {
deletedCells: notebook.model.deletedCells
})
.then(reply => {
notebook.model.deletedCells.splice(
0,
notebook.model.deletedCells.length
);
if (cell.isDisposed) {
return false;
}
if (!reply) {
return true;
}
if (reply.content.status === 'ok') {
cell.setPrompt('');
}
});
}
cell.model.contentChanged.disconnect(this.update, this);
this.update();
this._executed.emit(new Date());
};
let onFailure = () => {
if (this.isDisposed) {
return;
}
cell.model.contentChanged.disconnect(this.update, this);
this.update();
};
return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
}
cell.setPrompt('');
}
});
}
listener.dispose();
this.update();
this._executed.emit(new Date());
};
let onFailure = () => {
if (this.isDisposed) {
return;
}
listener.dispose();
this.update();
};
return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
}