forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Activate the deferred plugins after shell restore (jupyterlab#14610)
* Activate the deferred plugins after shell restore * Update packages/application/src/lab.ts Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com> * Update packages/application/src/lab.ts Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com> * fix lint * Remove try/catch when activating deferred extensions * Add a promise to the application for deferred plugins activation, and add tests on plugin activation * lint --------- Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
- Loading branch information
1 parent
6638a23
commit 0ec915d
Showing
3 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { | ||
JupyterFrontEndPlugin, | ||
JupyterLab, | ||
LayoutRestorer | ||
} from '@jupyterlab/application'; | ||
import { StateDB } from '@jupyterlab/statedb'; | ||
import { CommandRegistry } from '@lumino/commands'; | ||
import { DockPanel } from '@lumino/widgets'; | ||
|
||
describe('plugins', () => { | ||
let lab: JupyterLab; | ||
let plugin: JupyterFrontEndPlugin<void> = { | ||
id: '@jupyterlab/test-extension:plugin', | ||
autoStart: true, | ||
activate: async () => { | ||
await new Promise(f => setTimeout(f, 5000)); | ||
} | ||
}; | ||
|
||
beforeEach(() => { | ||
lab = new JupyterLab({}); | ||
}); | ||
|
||
it('autoStart plugin should be activated when application restore', async () => { | ||
lab.registerPlugin(plugin); | ||
await lab.start(); | ||
const restorer = new LayoutRestorer({ | ||
connector: new StateDB(), | ||
first: Promise.resolve<void>(void 0), | ||
registry: new CommandRegistry() | ||
}); | ||
const mode: DockPanel.Mode = 'multiple-document'; | ||
void lab.shell.restoreLayout(mode, restorer); | ||
await lab.restored; | ||
expect( | ||
lab.isPluginActivated('@jupyterlab/test-extension:plugin') | ||
).toBeTruthy(); | ||
}); | ||
|
||
it('autoStart=false plugin should never be activated', async () => { | ||
plugin.autoStart = false; | ||
lab.registerPlugin(plugin); | ||
await lab.start(); | ||
const restorer = new LayoutRestorer({ | ||
connector: new StateDB(), | ||
first: Promise.resolve<void>(void 0), | ||
registry: new CommandRegistry() | ||
}); | ||
const mode: DockPanel.Mode = 'multiple-document'; | ||
void lab.shell.restoreLayout(mode, restorer); | ||
await lab.restored; | ||
expect( | ||
lab.isPluginActivated('@jupyterlab/test-extension:plugin') | ||
).toBeFalsy(); | ||
await lab.allPluginsActivated; | ||
expect( | ||
lab.isPluginActivated('@jupyterlab/test-extension:plugin') | ||
).toBeFalsy(); | ||
}); | ||
|
||
it('deferred plugin should not be activated right after application restore', async () => { | ||
plugin.autoStart = 'defer'; | ||
lab.registerPlugin(plugin); | ||
await lab.start(); | ||
const restorer = new LayoutRestorer({ | ||
connector: new StateDB(), | ||
first: Promise.resolve<void>(void 0), | ||
registry: new CommandRegistry() | ||
}); | ||
const mode: DockPanel.Mode = 'multiple-document'; | ||
void lab.shell.restoreLayout(mode, restorer); | ||
await lab.restored; | ||
expect( | ||
lab.isPluginActivated('@jupyterlab/test-extension:plugin') | ||
).toBeFalsy(); | ||
await lab.allPluginsActivated; | ||
expect( | ||
lab.isPluginActivated('@jupyterlab/test-extension:plugin') | ||
).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters