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 connect to an existing kernel', async () => {
// Shut down and dispose the session so it can be re-instantiated.
await session.shutdown();
session.dispose();
const other = await manager.startNew({ path: UUID.uuid4() });
const kernelPreference = { id: other.kernel.id };
session = new ClientSession({ manager, kernelPreference });
await session.initialize();
expect(session.kernel.id).to.equal(other.kernel.id);
// We don't call other.shutdown() here because that
// is handled by the afterEach() handler above.
other.dispose();
});
function main(): void {
const manager = new SessionManager();
const session = new ClientSession({ manager, name: 'Example' });
const mimeService = new CodeMirrorMimeTypeService();
// Initialize the command registry with the bindings.
const commands = new CommandRegistry();
const useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener(
'keydown',
event => {
commands.processKeydownEvent(event);
},
useCapture
);
// Create the cell widget with a default rendermime instance.
function main(): void {
const manager = new SessionManager();
const session = new ClientSession({ manager, name: 'Example' });
const mimeService = new CodeMirrorMimeTypeService();
// Initialize the command registry with the bindings.
const commands = new CommandRegistry();
const useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener(
'keydown',
event => {
commands.processKeydownEvent(event);
},
useCapture
);
// Create the cell widget with a default rendermime instance.
beforeEach(() => {
Dialog.flush();
session = new ClientSession({
manager,
kernelPreference: { name: manager.specs.default }
});
});
export async function createClientSession(
options: Partial = {}
): Promise {
const manager = options.manager || Private.manager.sessions;
await manager.ready;
return new ClientSession({
manager,
path: options.path || UUID.uuid4(),
name: options.name,
type: options.type,
kernelPreference: options.kernelPreference || {
shouldStart: true,
canStart: true,
name: manager.specs.default
}
});
}
export async function createClientSession(
options: Partial = {}
): Promise {
const manager = options.manager || Private.getManager().sessions;
await manager.ready;
return new ClientSession({
manager,
path: options.path || UUID.uuid4(),
name: options.name,
type: options.type,
kernelPreference: options.kernelPreference || {
shouldStart: true,
canStart: true,
name: manager.specs.default
}
});
}
beforeEach(() => {
Dialog.flush();
session = new ClientSession({
manager,
kernelPreference: { name: manager.specs.default }
});
});
constructor(options: ConsolePanel.IOptions) {
super();
this.addClass(PANEL_CLASS);
let {
rendermime, mimeTypeService, path, basePath, name, manager, modelFactory
} = options;
let contentFactory = this.contentFactory = (
options.contentFactory || ConsolePanel.defaultContentFactory
);
let count = Private.count++;
if (!path) {
path = `${basePath || ''}/console-${count}-${uuid()}`;
}
let session = this._session = new ClientSession({
manager: manager.sessions,
path,
name: name || `Console ${count}`,
type: 'console',
kernelPreference: options.kernelPreference
});
let resolver = new RenderMime.UrlResolver({
session,
contents: manager.contents
});
rendermime = rendermime.clone({ resolver });
this.console = contentFactory.createConsole({
rendermime, session, mimeTypeService, contentFactory, modelFactory
});
rendermime,
mimeTypeService,
path,
basePath,
name,
manager,
modelFactory
} = options;
let contentFactory = (this.contentFactory =
options.contentFactory || ConsolePanel.defaultContentFactory);
let count = Private.count++;
if (!path) {
path = `${basePath || ''}/console-${count}-${UUID.uuid4()}`;
}
let session = (this._session = new ClientSession({
manager: manager.sessions,
path,
name: name || `Console ${count}`,
type: 'console',
kernelPreference: options.kernelPreference,
setBusy: options.setBusy
}));
let resolver = new RenderMimeRegistry.UrlResolver({
session,
contents: manager.contents
});
rendermime = rendermime.clone({ resolver });
this.console = contentFactory.createConsole({
rendermime,
let dbFactory = options.modelDBFactory;
if (dbFactory) {
const localPath = manager.contents.localPath(this._path);
this._modelDB = dbFactory.createNew(localPath);
this._model = this._factory.createNew(lang, this._modelDB);
} else {
this._model = this._factory.createNew(lang);
}
this._readyPromise = manager.ready.then(() => {
return this._populatedPromise.promise;
});
let ext = PathExt.extname(this._path);
this.session = new ClientSession({
manager: manager.sessions,
path: this._path,
type: ext === '.ipynb' ? 'notebook' : 'file',
name: PathExt.basename(localPath),
kernelPreference: options.kernelPreference || { shouldStart: false },
setBusy: options.setBusy
});
this.session.propertyChanged.connect(this._onSessionChanged, this);
manager.contents.fileChanged.connect(this._onFileChanged, this);
this.urlResolver = new RenderMimeRegistry.UrlResolver({
session: this.session,
contents: manager.contents
});
}