Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var services = require('@jupyterlab/services');
// Start a new session.
var options = {
path: 'foo.ipynb',
type: 'notebook',
name: 'foo.ipynb',
kernel: {
name: 'python'
}
};
/* eslint-disable no-console */
console.log('Starting session...');
var kernelManager = new services.KernelManager();
var sessionManager = new services.SessionManager({ kernelManager });
var session;
sessionManager
.startNew(options)
.then(function(s) {
// Rename the session.
session = s;
return session.setPath('bar.ipynb');
})
.then(function() {
console.log('Session renamed to', session.path);
// Execute and handle replies on the kernel.
var future = session.kernel.requestExecute({ code: 'a = 1' });
future.onReply = function(reply) {
console.log('Got execute reply', reply);
};
return future.done;
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
);
it('should get the server settings', () => {
manager.dispose();
const serverSettings = ServerConnection.makeSettings();
const token = serverSettings.token;
manager = new SessionManager({ serverSettings });
expect(manager.serverSettings.token).to.equal(token);
});
});
it('should test whether the manager is ready', async () => {
manager.dispose();
manager = new SessionManager();
expect(manager.isReady).to.equal(false);
await manager.ready;
expect(manager.isReady).to.equal(true);
});
});
it('should get the server settings', () => {
manager.dispose();
const serverSettings = ServerConnection.makeSettings();
const token = serverSettings.token;
manager = new SessionManager({ serverSettings });
expect(manager.serverSettings.token).to.equal(token);
});
});
describe('ClientSession', () => {
const manager = new SessionManager();
let session: ClientSession;
beforeAll(() => manager.ready);
beforeEach(() => {
Dialog.flush();
session = new ClientSession({
manager,
kernelPreference: { name: manager.specs.default }
});
});
afterEach(async () => {
Dialog.flush();
try {
await session.shutdown();
beforeEach(() => {
manager = new SessionManager();
expect(manager.specs).to.be.null;
});
beforeEach(() => {
manager = new SessionManager();
expect(manager.specs).to.be.null;
});
describe('ClientSession', () => {
const manager = new SessionManager();
let session: ClientSession;
beforeAll(() => manager.ready);
beforeEach(() => {
Dialog.flush();
session = new ClientSession({
manager,
kernelPreference: { name: manager.specs.default }
});
});
afterEach(async () => {
Dialog.flush();
try {
await session.shutdown();
public async initialize(connInfo: IConnection): Promise {
this.connInfo = connInfo;
this.serverSettings = await this.getServerConnectSettings(connInfo);
this.sessionManager = new SessionManager({ serverSettings: this.serverSettings });
this.contentsManager = new ContentsManager({ serverSettings: this.serverSettings });
}