Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Nov 1, 2023
1 parent 4fa705b commit 8c77d41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
40 changes: 24 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,12 @@ const consoles: JupyterFrontEndPlugin<void> = {
});
});
}

setSource(labShell);
});

/**
* If focus window changes, checks whether new focus widget is a console.
* In that case, retrieves the handler associated to the console after it has been
* initialized and updates the manager with it.
*/
labShell.currentChanged.connect((sender, args) => {
const widget = args.newValue;
const setSource = (sender: ILabShell, args?: ILabShell.IChangedArgs) => {
const widget = args?.newValue ?? sender.currentWidget;
if (!widget || !consoles.has(widget)) {
return;
}
Expand All @@ -203,7 +200,14 @@ const consoles: JupyterFrontEndPlugin<void> = {
manager.source.performInspection();
}
});
});
};
/**
* If focus window changes, checks whether new focus widget is a console.
* In that case, retrieves the handler associated to the console after it has been
* initialized and updates the manager with it.
*/
setSource(labShell);
labShell.currentChanged.connect(setSource);

app.contextMenu.addItem({
command: CommandIDs.open,
Expand Down Expand Up @@ -279,15 +283,12 @@ const notebooks: JupyterFrontEndPlugin<void> = {
reject(result);
});
});

setSource(labShell);
});

/**
* If focus window changes, checks whether new focus widget is a notebook.
* In that case, retrieves the handler associated to the notebook after it has been
* initialized and updates the manager with it.
*/
labShell.currentChanged.connect((sender, args) => {
const widget = args.newValue;
const setSource = (sender: ILabShell, args?: ILabShell.IChangedArgs) => {
const widget = args?.newValue ?? sender.currentWidget;
if (!widget || !notebooks.has(widget) || widget.isDisposed) {
return;
}
Expand All @@ -298,7 +299,14 @@ const notebooks: JupyterFrontEndPlugin<void> = {
manager.source.performInspection();
}
});
});
};
/**
* If focus window changes, checks whether new focus widget is a notebook.
* In that case, retrieves the handler associated to the notebook after it has been
* initialized and updates the manager with it.
*/
setSource(labShell);
labShell.currentChanged.connect(setSource);

app.contextMenu.addItem({
command: CommandIDs.open,
Expand Down
28 changes: 13 additions & 15 deletions ui-tests/tests/lckr_jupyterlab_variableinspector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { expect, test } from '@jupyterlab/galata';

/**
* Don't load JupyterLab webpage before running the tests.
* This is required to ensure we capture all log messages.
*/
test.use({ autoGoto: false });

test('should emit an activation console message', async ({ page }) => {
const logs: string[] = [];
test('test', async ({ page }) => {
await page.getByText('Python 3 (ipykernel)').first().click();
await page.getByText('Python 3 (ipykernel) | Idle').waitFor();
await page.getByLabel('notebook content').getByRole('textbox').fill('a = 1');
await page.keyboard.press('Shift+Enter');
await page.getByRole('textbox').nth(2).fill('b = "hello"');
await page.keyboard.press('Control+Enter');

page.on('console', message => {
logs.push(message.text());
await page.getByRole('tabpanel').click({
button: 'right'
});
await page.getByRole('menu').getByText('Open Variable Inspector').click();

await page.goto();

expect(
logs.filter(s => s === 'JupyterLab extension @lckr/jupyterlab_variableinspector is activated!')
).toHaveLength(1);
});
await expect(page.getByRole('row').nth(1)).toHaveText(/aint281$/)
await expect(page.getByRole('row').last()).toHaveText(/bstr46hello$/)
});

0 comments on commit 8c77d41

Please sign in to comment.