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 return an empty notebook for empty file", () => {
store.updateEditor(editor);
// Build a notebook with one code cell.
const nb = commutable.emptyNotebook;
expect(store.notebook).toEqual(commutable.toJS(nb));
});
it("should return a fully-fledged notebook when the file isn't empty", () => {
const source1 = 'print("Hola World! I <3 ZMQ!")';
const source2 = "2 + 2";
editor.setText(`# %%\n${source1}\n# %%\n${source2}\n`);
store.updateEditor(editor);
const codeCell1 = commutable.emptyCodeCell.set("source", source1);
const codeCell2 = commutable.emptyCodeCell.set("source", source2);
// The outputted notebook will have three cells because currently a cell
// is always created before the first `# %%`
let nb = commutable.appendCellToNotebook(
commutable.emptyNotebook,
codeCell1
);
nb = commutable.appendCellToNotebook(nb, codeCell2);
expect(store.notebook).toEqual(commutable.toJS(nb));
});
get notebook() {
const editor = this.editor;
if (!editor) return null;
let notebook = commutable.emptyNotebook;
if (this.kernel) {
notebook = notebook.setIn(
["metadata", "kernelspec"],
this.kernel.transport.kernelSpec
);
}
const cellRanges = codeManager.getCells(editor);
_.forEach(cellRanges, cell => {
const { start, end } = cell;
let source = codeManager.getTextInRange(editor, start, end);
source = source ? source : "";
// When the cell marker following a given cell range is on its own line,
// the newline immediately preceding that cell marker is included in
// `source`. We remove that here. See #1512 for more details.
if (source.slice(-1) === "\n") source = source.slice(0, -1);
const cellType = codeManager.getMetadataForRow(editor, start);