|
@@ -1,7 +1,7 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import { expect } from 'chai';
|
|
|
+import 'jest';
|
|
|
|
|
|
import { Message, MessageLoop } from '@lumino/messaging';
|
|
|
|
|
@@ -9,7 +9,7 @@ import { Widget } from '@lumino/widgets';
|
|
|
|
|
|
import { SessionContext } from '@jupyterlab/apputils';
|
|
|
|
|
|
-import { CodeConsole } from '@jupyterlab/console';
|
|
|
+import { CodeConsole } from '../src';
|
|
|
|
|
|
import {
|
|
|
CodeCell,
|
|
@@ -76,14 +76,16 @@ describe('console/widget', () => {
|
|
|
describe('#constructor()', () => {
|
|
|
it('should create a new console content widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget).to.be.an.instanceof(CodeConsole);
|
|
|
- expect(Array.from(widget.node.classList)).to.contain('jp-CodeConsole');
|
|
|
+ expect(widget).toBeInstanceOf(CodeConsole);
|
|
|
+ expect(Array.from(widget.node.classList)).toEqual(
|
|
|
+ expect.arrayContaining(['jp-CodeConsole'])
|
|
|
+ );
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#cells', () => {
|
|
|
it('should exist upon instantiation', () => {
|
|
|
- expect(widget.cells).to.be.ok;
|
|
|
+ expect(widget.cells).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
it('should reflect the contents of the widget', async () => {
|
|
@@ -91,9 +93,9 @@ describe('console/widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
await (widget.sessionContext as SessionContext).initialize();
|
|
|
await widget.execute(force);
|
|
|
- expect(widget.cells.length).to.equal(1);
|
|
|
+ expect(widget.cells.length).toBe(1);
|
|
|
widget.clear();
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -107,14 +109,14 @@ describe('console/widget', () => {
|
|
|
});
|
|
|
await (widget.sessionContext as SessionContext).initialize();
|
|
|
await widget.execute(force);
|
|
|
- expect(called).to.be.an.instanceof(Date);
|
|
|
+ expect(called).toBeInstanceOf(Date);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#promptCell', () => {
|
|
|
it('should be a code cell widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.promptCell).to.be.an.instanceof(CodeCell);
|
|
|
+ expect(widget.promptCell).toBeInstanceOf(CodeCell);
|
|
|
});
|
|
|
|
|
|
it('should be replaced after execution', async () => {
|
|
@@ -122,24 +124,24 @@ describe('console/widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
|
|
|
const old = widget.promptCell;
|
|
|
- expect(old).to.be.an.instanceof(CodeCell);
|
|
|
+ expect(old).toBeInstanceOf(CodeCell);
|
|
|
|
|
|
await (widget.sessionContext as SessionContext).initialize();
|
|
|
await widget.execute(force);
|
|
|
- expect(widget.promptCell).to.be.an.instanceof(CodeCell);
|
|
|
- expect(widget.promptCell).to.not.equal(old);
|
|
|
+ expect(widget.promptCell).toBeInstanceOf(CodeCell);
|
|
|
+ expect(widget.promptCell).not.toBe(old);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#session', () => {
|
|
|
it('should be a client session object', () => {
|
|
|
- expect(widget.sessionContext.sessionChanged).to.be.ok;
|
|
|
+ expect(widget.sessionContext.sessionChanged).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#contentFactory', () => {
|
|
|
it('should be the content factory used by the widget', () => {
|
|
|
- expect(widget.contentFactory).to.be.an.instanceof(
|
|
|
+ expect(widget.contentFactory).toBeInstanceOf(
|
|
|
CodeConsole.ContentFactory
|
|
|
);
|
|
|
});
|
|
@@ -155,9 +157,9 @@ describe('console/widget', () => {
|
|
|
rendermime
|
|
|
}).initializeState();
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
widget.addCell(cell);
|
|
|
- expect(widget.cells.length).to.equal(1);
|
|
|
+ expect(widget.cells.length).toBe(1);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -167,27 +169,27 @@ describe('console/widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
await (widget.sessionContext as SessionContext).initialize();
|
|
|
await widget.execute(force);
|
|
|
- expect(widget.cells.length).to.be.greaterThan(0);
|
|
|
+ expect(widget.cells.length).toBeGreaterThan(0);
|
|
|
widget.clear();
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
- expect(widget.promptCell!.model.value.text).to.equal('');
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
+ expect(widget.promptCell!.model.value.text).toBe('');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#dispose()', () => {
|
|
|
it('should dispose the content widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.isDisposed).to.equal(false);
|
|
|
+ expect(widget.isDisposed).toBe(false);
|
|
|
widget.dispose();
|
|
|
- expect(widget.isDisposed).to.equal(true);
|
|
|
+ expect(widget.isDisposed).toBe(true);
|
|
|
});
|
|
|
|
|
|
it('should be safe to dispose multiple times', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.isDisposed).to.equal(false);
|
|
|
+ expect(widget.isDisposed).toBe(false);
|
|
|
widget.dispose();
|
|
|
widget.dispose();
|
|
|
- expect(widget.isDisposed).to.equal(true);
|
|
|
+ expect(widget.isDisposed).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -195,10 +197,10 @@ describe('console/widget', () => {
|
|
|
it('should execute contents of the prompt if forced', async () => {
|
|
|
const force = true;
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
await (widget.sessionContext as SessionContext).initialize();
|
|
|
await widget.execute(force);
|
|
|
- expect(widget.cells.length).to.be.greaterThan(0);
|
|
|
+ expect(widget.cells.length).toBeGreaterThan(0);
|
|
|
});
|
|
|
|
|
|
it('should check if code is multiline and allow amending', async () => {
|
|
@@ -206,12 +208,12 @@ describe('console/widget', () => {
|
|
|
const timeout = 9000;
|
|
|
Widget.attach(widget, document.body);
|
|
|
widget.promptCell!.model.value.text = 'for x in range(5):';
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
const session = widget.sessionContext as SessionContext;
|
|
|
session.kernelPreference = { name: 'ipython' };
|
|
|
await session.initialize();
|
|
|
await widget.execute(force, timeout);
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -219,9 +221,9 @@ describe('console/widget', () => {
|
|
|
it('should add a code cell and execute it', async () => {
|
|
|
const code = 'print("#inject()")';
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.cells.length).to.equal(0);
|
|
|
+ expect(widget.cells.length).toBe(0);
|
|
|
await widget.inject(code);
|
|
|
- expect(widget.cells.length).to.be.greaterThan(0);
|
|
|
+ expect(widget.cells.length).toBeGreaterThan(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -230,9 +232,9 @@ describe('console/widget', () => {
|
|
|
Widget.attach(widget, document.body);
|
|
|
|
|
|
const model = widget.promptCell!.model;
|
|
|
- expect(model.value.text).to.be.empty;
|
|
|
+ expect(model.value.text).toHaveLength(0);
|
|
|
widget.insertLinebreak();
|
|
|
- expect(model.value.text).to.equal('\n');
|
|
|
+ expect(model.value.text).toBe('\n');
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -242,58 +244,76 @@ describe('console/widget', () => {
|
|
|
widget.promptCell!.model.value.text = 'foo';
|
|
|
|
|
|
const serialized = widget.serialize();
|
|
|
- expect(serialized).to.have.length(1);
|
|
|
- expect(serialized[0].source).to.equal('foo');
|
|
|
+ expect(serialized).toHaveLength(1);
|
|
|
+ expect(serialized[0].source).toBe('foo');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#newPromptCell()', () => {
|
|
|
it('should be called after attach, creating a prompt', () => {
|
|
|
- expect(widget.promptCell).to.not.be.ok;
|
|
|
- expect(widget.methods).to.not.contain('newPromptCell');
|
|
|
+ expect(widget.promptCell).toBeFalsy();
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.not.arrayContaining(['newPromptCell'])
|
|
|
+ );
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.methods).to.contain('newPromptCell');
|
|
|
- expect(widget.promptCell).to.be.ok;
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.arrayContaining(['newPromptCell'])
|
|
|
+ );
|
|
|
+ expect(widget.promptCell).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
it('should be called after execution, creating a prompt', async () => {
|
|
|
- expect(widget.promptCell).to.not.be.ok;
|
|
|
- expect(widget.methods).to.not.contain('newPromptCell');
|
|
|
+ expect(widget.promptCell).toBeFalsy();
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.not.arrayContaining(['newPromptCell'])
|
|
|
+ );
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.methods).to.contain('newPromptCell');
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.arrayContaining(['newPromptCell'])
|
|
|
+ );
|
|
|
|
|
|
const old = widget.promptCell;
|
|
|
const force = true;
|
|
|
- expect(old).to.be.an.instanceof(CodeCell);
|
|
|
+ expect(old).toBeInstanceOf(CodeCell);
|
|
|
widget.methods = [];
|
|
|
|
|
|
await (widget.sessionContext as SessionContext).initialize();
|
|
|
await widget.execute(force);
|
|
|
|
|
|
- expect(widget.promptCell).to.be.an.instanceof(CodeCell);
|
|
|
- expect(widget.promptCell).to.not.equal(old);
|
|
|
- expect(widget.methods).to.contain('newPromptCell');
|
|
|
+ expect(widget.promptCell).toBeInstanceOf(CodeCell);
|
|
|
+ expect(widget.promptCell).not.toBe(old);
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.arrayContaining(['newPromptCell'])
|
|
|
+ );
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#onActivateRequest()', () => {
|
|
|
it('should focus the prompt editor', () => {
|
|
|
- expect(widget.promptCell).to.not.be.ok;
|
|
|
- expect(widget.methods).to.not.contain('onActivateRequest');
|
|
|
+ expect(widget.promptCell).toBeFalsy();
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.not.arrayContaining(['onActivateRequest'])
|
|
|
+ );
|
|
|
Widget.attach(widget, document.body);
|
|
|
MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
|
|
|
- expect(widget.methods).to.contain('onActivateRequest');
|
|
|
- expect(widget.promptCell!.editor.hasFocus()).to.equal(true);
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.arrayContaining(['onActivateRequest'])
|
|
|
+ );
|
|
|
+ expect(widget.promptCell!.editor.hasFocus()).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#onAfterAttach()', () => {
|
|
|
it('should be called after attach, creating a prompt', () => {
|
|
|
- expect(widget.promptCell).to.not.be.ok;
|
|
|
- expect(widget.methods).to.not.contain('onAfterAttach');
|
|
|
+ expect(widget.promptCell).toBeFalsy();
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.not.arrayContaining(['onAfterAttach'])
|
|
|
+ );
|
|
|
Widget.attach(widget, document.body);
|
|
|
- expect(widget.methods).to.contain('onAfterAttach');
|
|
|
- expect(widget.promptCell).to.be.ok;
|
|
|
+ expect(widget.methods).toEqual(
|
|
|
+ expect.arrayContaining(['onAfterAttach'])
|
|
|
+ );
|
|
|
+ expect(widget.promptCell).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -301,7 +321,7 @@ describe('console/widget', () => {
|
|
|
describe('#constructor', () => {
|
|
|
it('should create a new ContentFactory', () => {
|
|
|
const factory = new CodeConsole.ContentFactory({ editorFactory });
|
|
|
- expect(factory).to.be.an.instanceof(CodeConsole.ContentFactory);
|
|
|
+ expect(factory).toBeInstanceOf(CodeConsole.ContentFactory);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -313,7 +333,7 @@ describe('console/widget', () => {
|
|
|
model,
|
|
|
contentFactory
|
|
|
});
|
|
|
- expect(prompt).to.be.an.instanceof(CodeCell);
|
|
|
+ expect(prompt).toBeInstanceOf(CodeCell);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -324,7 +344,7 @@ describe('console/widget', () => {
|
|
|
model,
|
|
|
contentFactory
|
|
|
});
|
|
|
- expect(prompt).to.be.an.instanceof(RawCell);
|
|
|
+ expect(prompt).toBeInstanceOf(RawCell);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
@@ -333,7 +353,7 @@ describe('console/widget', () => {
|
|
|
describe('#constructor()', () => {
|
|
|
it('should create a new model factory', () => {
|
|
|
const factory = new CodeConsole.ModelFactory({});
|
|
|
- expect(factory).to.be.an.instanceof(CodeConsole.ModelFactory);
|
|
|
+ expect(factory).toBeInstanceOf(CodeConsole.ModelFactory);
|
|
|
});
|
|
|
|
|
|
it('should accept a codeCellContentFactory', () => {
|
|
@@ -341,16 +361,14 @@ describe('console/widget', () => {
|
|
|
const factory = new CodeConsole.ModelFactory({
|
|
|
codeCellContentFactory
|
|
|
});
|
|
|
- expect(factory.codeCellContentFactory).to.equal(
|
|
|
- codeCellContentFactory
|
|
|
- );
|
|
|
+ expect(factory.codeCellContentFactory).toBe(codeCellContentFactory);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#codeCellContentFactory', () => {
|
|
|
it('should be the code cell content factory used by the factory', () => {
|
|
|
const factory = new CodeConsole.ModelFactory({});
|
|
|
- expect(factory.codeCellContentFactory).to.equal(
|
|
|
+ expect(factory.codeCellContentFactory).toBe(
|
|
|
CodeCellModel.defaultContentFactory
|
|
|
);
|
|
|
});
|
|
@@ -359,21 +377,21 @@ describe('console/widget', () => {
|
|
|
describe('#createCodeCell()', () => {
|
|
|
it('should create a code cell', () => {
|
|
|
const factory = new CodeConsole.ModelFactory({});
|
|
|
- expect(factory.createCodeCell({})).to.be.an.instanceof(CodeCellModel);
|
|
|
+ expect(factory.createCodeCell({})).toBeInstanceOf(CodeCellModel);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#createRawCell()', () => {
|
|
|
it('should create a raw cell model', () => {
|
|
|
const factory = new CodeConsole.ModelFactory({});
|
|
|
- expect(factory.createRawCell({})).to.be.an.instanceof(RawCellModel);
|
|
|
+ expect(factory.createRawCell({})).toBeInstanceOf(RawCellModel);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('.defaultModelFactory', () => {
|
|
|
it('should be a ModelFactory', () => {
|
|
|
- expect(CodeConsole.defaultModelFactory).to.be.an.instanceof(
|
|
|
+ expect(CodeConsole.defaultModelFactory).toBeInstanceOf(
|
|
|
CodeConsole.ModelFactory
|
|
|
);
|
|
|
});
|