Skip to content

Commit

Permalink
Fix visual tests, allow to disable termianal cursor blinking (jupyter…
Browse files Browse the repository at this point in the history
…lab#15524)

* Make the completer test more robust

* Move overview tests which require running in serial

* More robust readonly toast test

* Try to make the test terminal snapshot more robust

by mock `tree . -L 2` command

* Workaround `test-` dirs issue by capturing `/data` instead of `/`

* Update Playwright Snapshots

* Run customization docs snapshots in serial

* Ignore all test files in galata tests

* Expose configuration for cursor blinking in terminal, disable in tests

To fix flaky terminal tests

* Update Playwright Snapshots

* Update Playwright Snapshots

* Disable concurrency in `build:examples` to fix flaky test

This was already use in `build:src`

* Ensure no flaky focus indicator on snapshot

* Try to tune throttling

* Check browser before starting CPD session

Co-authored-by: Frédéric Collonval <[email protected]>

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frédéric Collonval <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2023
1 parent 746ce2d commit c26a0e7
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ header:
- 'dev_mode/style.js'
- 'examples/federated/example.cert'
- 'galata/test/jupyterlab/notebooks/'
- 'galata/test/*/*-snapshots/*.txt'
- 'galata/test/*/*/*.txt'
- 'jupyterlab.desktop'
- 'jupyterlab/staging'
- 'packages/codemirror/test/foo.grammar'
Expand Down
3 changes: 3 additions & 0 deletions galata/src/galata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export namespace galata {
defaultConfig: {
cursorBlinkRate: 0
}
},
'@jupyterlab/terminal-extension:plugin': {
cursorBlink: false
}
};

Expand Down
24 changes: 23 additions & 1 deletion galata/src/helpers/performance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Page } from '@playwright/test';
import { CDPSession, Page } from '@playwright/test';
import { UUID } from '@lumino/coreutils';

/**
Expand Down Expand Up @@ -40,6 +40,28 @@ export class PerformanceHelper {
return time;
}

/**
* Throttle network
*/
async throttleNetwork(config: {
downloadThroughput: number;
uploadThroughput: number;
latency: number;
}): Promise<CDPSession | null> {
const context = this.page.context();
const browserName = context.browser()!.browserType().name();
if (browserName === 'chromium') {
const cdpSession = await context.newCDPSession(this.page);
await cdpSession.send('Network.emulateNetworkConditions', {
offline: false,
...config
});
return cdpSession;
}
console.log('Browser does not support throttling network');
return null;
}

/**
* Measure the time to execute a function using web browser performance API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1999,9 +1999,7 @@
"id": "notebook:toggle-all-cell-line-numbers",
"label": "Show Line Numbers",
"caption": "",
"shortcuts": [
"Shift L"
]
"shortcuts": []
},
{
"id": "notebook:toggle-autoclosing-brackets",
Expand Down
3 changes: 3 additions & 0 deletions galata/test/documentation/customization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ test.use({
viewport: { height: 720, width: 1280 }
});

// Use serial mode to avoid flaky screenshots
test.describe.configure({ mode: 'serial' });

test.describe('Default', () => {
test('should use default layout', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
Expand Down
37 changes: 37 additions & 0 deletions galata/test/documentation/data/tree_fixture.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$ tree . -L 2
.
├── LICENSE
├── README.md
├── data
│   ├── 1024px-Hubble_Interacting_Galaxy_AM_0500-620_(2008-04-24).jpg
│   ├── Dockerfile
│   ├── Museums_in_DC.geojson
│   ├── README.md
│   ├── bar.vl.json
│   ├── iris.csv
│   ├── japan_meterological_agency_201707211555.json
│   └── zika_assembled_genomes.fasta
├── jupyter_notebook_config.py
├── narrative
│   ├── QConAI.md
│   ├── jupyterlab.md
│   ├── markdown_python.md
│   └── scipy2017.md
├── notebooks
│   ├── Cpp.ipynb
│   ├── Data.ipynb
│   ├── Fasta.ipynb
│   ├── Julia.ipynb
│   ├── Lorenz.ipynb
│   ├── R.ipynb
│   ├── audio
│   ├── images
│   └── lorenz.py
├── slides
│   ├── jupyterlab-slides.key
│   ├── jupyterlab-slides.pdf
│   └── jupyterlab-slides_scipy19.pdf
├── talks.yml
└── tasks.py

6 directories, 27 files
110 changes: 11 additions & 99 deletions galata/test/documentation/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the terms of the Modified BSD License.

import { expect, galata, test } from '@jupyterlab/galata';
import path from 'path';
import {
generateArrow,
positionMouse,
Expand Down Expand Up @@ -79,13 +80,6 @@ test.describe('General', () => {
expect(await page.screenshot()).toMatchSnapshot('jupyterlab.png');
});

test('Overview', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await openOverview(page);

expect(await page.screenshot()).toMatchSnapshot('interface_jupyterlab.png');
});

test('Left Sidebar', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await page.goto();
Expand All @@ -98,6 +92,8 @@ test.describe('General', () => {
await setSidebarWidth(page);

await page.dblclick('[aria-label="File Browser Section"] >> text=data');
// Wait for the `data` folder to load to have something to blur
await page.waitForSelector('text=1024px');

await page.evaluate(() => {
(document.activeElement as HTMLElement).blur();
Expand Down Expand Up @@ -228,32 +224,6 @@ test.describe('General', () => {
);
});

test('Open tabs', async ({ page }) => {
await openOverview(page);

await page.click('[title="Running Terminals and Kernels"]');

await page
.locator(
'.jp-RunningSessions-item.jp-mod-kernel >> text="Python 3 (ipykernel)"'
)
.waitFor();
expect(
await page.screenshot({ clip: { y: 27, x: 0, width: 283, height: 400 } })
).toMatchSnapshot('interface_tabs.png');
});

test('Tabs menu', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await openOverview(page);

await page.click('text="Tabs"');

expect(
await page.screenshot({ clip: { y: 0, x: 210, width: 700, height: 350 } })
).toMatchSnapshot('interface_tabs_menu.png');
});

test('File menu', async ({ page }) => {
await page.goto();
await page.addStyleTag({
Expand Down Expand Up @@ -532,8 +502,13 @@ test.describe('General', () => {
);
});

test('Terminals', async ({ page }) => {
test('Terminal layout', async ({ page, tmpPath }) => {
await galata.Mock.freezeContentLastModified(page);
const fileName = 'tree_fixture.txt';
await page.contents.uploadFile(
path.resolve(__dirname, `./data/${fileName}`),
`${tmpPath}/${fileName}`
);
await page.goto();
await page.addStyleTag({
content: `.jp-LabShell.jp-mod-devMode {
Expand All @@ -559,7 +534,7 @@ test.describe('General', () => {

await page.keyboard.type('cd $JUPYTERLAB_GALATA_ROOT_DIR');
await page.keyboard.press('Enter');
await page.keyboard.type('tree . -L 2');
await page.keyboard.type(`clear && cat ${tmpPath}/${fileName}`);
await page.keyboard.press('Enter');

// Wait for command answer
Expand Down Expand Up @@ -634,6 +609,7 @@ test.describe('General', () => {

await setSidebarWidth(page);

await page.dblclick('[aria-label="File Browser Section"] >> text=data');
await page.click('text=README.md', {
button: 'right'
});
Expand Down Expand Up @@ -710,67 +686,3 @@ test.describe('General', () => {
});
});
});

async function openOverview(page) {
await page.goto();
await page.addStyleTag({
content: `.jp-LabShell.jp-mod-devMode {
border-top: none;
}`
});

await setSidebarWidth(page);

// Open Data.ipynb
await page.dblclick('[aria-label="File Browser Section"] >> text=notebooks');
await page.dblclick('text=Data.ipynb');

// Back home
await page.click('.jp-BreadCrumbs-home svg');

// Open jupyterlab.md
await page.dblclick('[aria-label="File Browser Section"] >> text=narrative');
await page.click('text=jupyterlab.md', {
button: 'right'
});
await page.click('text=Open With');
await page.click('text=Markdown Preview');

// Back home
await page.click('.jp-BreadCrumbs-home svg');

// Open bar.vl.json
await page.dblclick('[aria-label="File Browser Section"] >> text=data');
await page.dblclick('text=bar.vl.json');
await page.dblclick(
'text=1024px-Hubble_Interacting_Galaxy_AM_0500-620_(2008-04-24).jpg'
);

// Move notebook panel
const notebookHandle = await page.$('div[role="main"] >> text=Data.ipynb');
await notebookHandle.click();
const notebookBBox = await notebookHandle.boundingBox();

await page.mouse.move(
notebookBBox.x + 0.5 * notebookBBox.width,
notebookBBox.y + 0.5 * notebookBBox.height
);
await page.mouse.down();
await page.mouse.move(notebookBBox.x + 0.5 * notebookBBox.width, 350);
await page.mouse.up();

// Move md panel
const mdHandle = await page.$('div[role="main"] >> text=jupyterlab.md');
await mdHandle.click();
const mdBBox = await mdHandle.boundingBox();
const panelHandle = await page.activity.getPanel();
const panelBBox = await panelHandle.boundingBox();

await page.mouse.move(
mdBBox.x + 0.5 * mdBBox.width,
mdBBox.y + 0.5 * mdBBox.height
);
await page.mouse.down();
await page.mouse.move(panelBBox.x + 0.5 * panelBBox.width, 200);
await page.mouse.up();
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions galata/test/documentation/internationalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ test.describe('Internationalization', () => {
await galata.Mock.freezeContentLastModified(page);
await page.goto();

await page.dblclick('[aria-label="File Browser Section"] >> text=data');

await page.click('text=Settings');
await page.click('.lm-Menu ul[role="menu"] >> text=Language');
await page.click('#jp-mainmenu-settings-language >> text=Chinese');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c26a0e7

Please sign in to comment.