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 accept server settings', () => {
const id = defaultKernel.id;
const serverSettings = makeSettings();
const kernel = Kernel.connectTo(defaultKernel.model, serverSettings);
expect(kernel.id).to.equal(id);
kernel.dispose();
});
it('should dispose of all kernel instances', async () => {
const kernel0 = await Kernel.startNew();
const kernel1 = Kernel.connectTo(kernel0.model);
await kernel0.ready;
await kernel1.ready;
await kernel0.shutdown();
expect(kernel0.isDisposed).to.equal(true);
expect(kernel1.isDisposed).to.equal(true);
});
});
it('should be safe to call multiple times', () => {
const kernel = Kernel.connectTo(defaultKernel.model);
expect(kernel.isDisposed).to.equal(false);
expect(kernel.isDisposed).to.equal(false);
kernel.dispose();
expect(kernel.isDisposed).to.equal(true);
expect(kernel.isDisposed).to.equal(true);
});
});
it('should be true after we dispose of the kernel', () => {
const kernel = Kernel.connectTo(defaultKernel.model);
expect(kernel.isDisposed).to.equal(false);
kernel.dispose();
expect(kernel.isDisposed).to.equal(true);
});
it('should accept server settings', () => {
const id = defaultKernel.id;
const serverSettings = makeSettings();
const kernel = Kernel.connectTo(defaultKernel.model, serverSettings);
expect(kernel.id).to.equal(id);
kernel.dispose();
});
});
it('should connect to an existing kernel', () => {
const id = defaultKernel.id;
const kernel = Kernel.connectTo(defaultKernel.model);
expect(kernel.id).to.equal(id);
kernel.dispose();
});
it('should be safe to call twice', () => {
const kernel = Kernel.connectTo(defaultKernel.model);
const future = kernel.requestExecute({ code: 'foo' });
expect(future.isDisposed).to.equal(false);
kernel.dispose();
expect(future.isDisposed).to.equal(true);
expect(kernel.isDisposed).to.equal(true);
kernel.dispose();
expect(future.isDisposed).to.equal(true);
expect(kernel.isDisposed).to.equal(true);
});
});
async renderWidgets() {
const baseUrl = PageConfig.getBaseUrl();
const kernelId = PageConfig.getOption('kernelId');
const connectionInfo = ServerConnection.makeSettings({baseUrl});
let model = await Kernel.findById(kernelId, connectionInfo);
let kernel = await Kernel.connectTo(model, connectionInfo);
this._kernel = kernel;
const manager = new WidgetManager(kernel, this._loader);
}
.then(() => Kernel.connectTo(kernel.model))
.then(kernel => {
async function connectKernel(baseUrl, kernelId) {
baseUrl = baseUrl || PageConfig.getBaseUrl();
kernelId = kernelId || PageConfig.getOption('kernelId');
const connectionInfo = ServerConnection.makeSettings({ baseUrl });
let model = await Kernel.findById(kernelId, connectionInfo);
let kernel = await Kernel.connectTo(model, connectionInfo);
return kernel;
}