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 resolve after the reveal and context ready promises', async () => {
const x = Object.create(null);
const reveal = sleep(300, x);
const contextReady = Promise.all([context.ready, x]);
const widget = new DocumentWidget({ context, content, reveal });
expect(widget.isRevealed).to.equal(false);
// Our promise should resolve before the widget reveal promise.
expect(await Promise.race([widget.revealed, reveal])).to.equal(x);
// The context ready promise should also resolve first.
void context.initialize(true);
expect(
await Promise.race([widget.revealed, contextReady])
).to.deep.equal([undefined, x]);
// The widget.revealed promise should finally resolve.
expect(await widget.revealed).to.be.undefined;
});
});
before(() => {
const opener: DocumentManager.IWidgetOpener = {
open: widget => {
/* no op */
}
};
registry = new DocumentRegistry({
textModelFactory: new TextModelFactory()
});
serviceManager = new ServiceManager({ standby: 'never' });
manager = new DocumentManager({
registry,
opener,
manager: serviceManager
});
state = new StateDB();
});
before(async () => {
const opener: DocumentManager.IWidgetOpener = {
open: widget => {
/* no op */
}
};
registry = new DocumentRegistry({
textModelFactory: new TextModelFactory()
});
serviceManager = new ServiceManager({ standby: 'never' });
iconRegistry = defaultIconRegistry;
manager = new DocumentManager({
registry,
opener,
manager: serviceManager
});
const contents = serviceManager.contents;
await contents.newUntitled({ type: 'directory' });
await contents.newUntitled({ type: 'file' });
await contents.newUntitled({ type: 'notebook' });
});
beforeEach(() => {
const registry = new DocumentRegistry({ textModelFactory });
registry.addWidgetFactory(widgetFactory);
registry.addWidgetFactory(widgetFactoryShared);
DocumentRegistry.defaultFileTypes.forEach(ft => {
registry.addFileType(ft);
});
manager = new DocumentManager({
registry,
manager: services,
opener: {
open: (widget: Widget) => {
// no-op
}
}
});
});
beforeEach(() => {
const registry = new DocumentRegistry({ textModelFactory });
registry.addWidgetFactory(widgetFactory);
registry.addWidgetFactory(widgetFactoryShared);
DocumentRegistry.defaultFileTypes.forEach(ft => {
registry.addFileType(ft);
});
manager = new DocumentManager({
registry,
manager: services,
opener: {
open: (widget: Widget) => {
// no-op
}
}
});
});
// Setup the keydown listener for the document.
document.addEventListener('keydown', event => {
commands.processKeydownEvent(event);
}, useCapture);
let rendermime = new RenderMime({
initialFactories: defaultRendererFactories
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor.bind(
editorServices.factoryService);
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileExtensions: ['.ipynb'],
defaultFor: ['.ipynb'],
preferKernel: true,
let rendermime = new RenderMimeRegistry({
initialFactories: initialFactories,
latexTypesetter: new MathJaxTypesetter({
url: PageConfig.getOption('mathjaxUrl'),
config: PageConfig.getOption('mathjaxConfig')
})
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileTypes: ['notebook'],
defaultFor: ['notebook'],
preferKernel: true,
canStartKernel: true,
let rendermime = new RenderMimeRegistry({
initialFactories: initialFactories,
latexTypesetter: new MathJaxTypesetter({
url: PageConfig.getOption('mathjaxUrl'),
config: PageConfig.getOption('mathjaxConfig')
})
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileTypes: ['notebook'],
defaultFor: ['notebook'],
preferKernel: true,
canStartKernel: true,
// old context before opening the new context. This will make things much
// more consistent for the users, at the cost of some confusion about what
// models are and why sometimes they cannot open the same file in different
// widgets that have different models.
// Allow options to be passed when adding a sibling.
let adopter = (
widget: IDocumentWidget,
options?: DocumentRegistry.IOpenOptions
) => {
this._widgetManager.adoptWidget(context, widget);
this._opener.open(widget, options);
};
let modelDBFactory =
this.services.contents.getModelDBFactory(path) || undefined;
let context = new Context({
opener: adopter,
manager: this.services,
factory,
path,
kernelPreference,
modelDBFactory,
setBusy: this._setBusy
});
let handler = new SaveHandler({
context,
saveInterval: this.autosaveInterval
});
Private.saveHandlerProperty.set(context, handler);
void context.ready.then(() => {
if (this.autosave) {
handler.start();
// old context before opening the new context. This will make things much
// more consistent for the users, at the cost of some confusion about what
// models are and why sometimes they cannot open the same file in different
// widgets that have different models.
// Allow options to be passed when adding a sibling.
let adopter = (
widget: IDocumentWidget,
options?: DocumentRegistry.IOpenOptions
) => {
this._widgetManager.adoptWidget(context, widget);
this._opener.open(widget, options);
};
let modelDBFactory =
this.services.contents.getModelDBFactory(path) || undefined;
let context = new Context({
opener: adopter,
manager: this.services,
factory,
path,
kernelPreference,
modelDBFactory,
setBusy: this._setBusy
});
let handler = new SaveHandler({
context,
saveInterval: this.autosaveInterval
});
Private.saveHandlerProperty.set(context, handler);
context.ready.then(() => {
if (this.autosave) {
handler.start();