Skip to content

Commit ebac582

Browse files
brichetgithub-actions[bot]fcollonval
authored
Add UI-tests (#157)
* Ui-tests for collaboration panel * Adds user menu test * Add workflow * Automatic application of license header * Test clicking on collaborator name * fix test file * .github/workflows/test.yml * fix collaboration test * Fix pre-commit * Add more tests * Lint files * Lint notebook.spec.ts * Forget checkout step... * Don't wait for Python test for UI tests macOS is flaky * Skip the broken test for now * Skip flaky ten client tests for now --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Frédéric Collonval <[email protected]> Co-authored-by: Frédéric Collonval <[email protected]>
1 parent 749ddc3 commit ebac582

27 files changed

+5935
-11
lines changed

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ jobs:
109109
110110
test_minimum_versions:
111111
name: Test Minimum Versions
112+
needs: [pre-commit, test-js, test-py]
112113
timeout-minutes: 20
113114
runs-on: ubuntu-latest
114115
steps:
@@ -125,6 +126,7 @@ jobs:
125126
126127
test_prereleases:
127128
name: Test Prereleases
129+
needs: [pre-commit, test-js, test-py]
128130
runs-on: ubuntu-latest
129131
timeout-minutes: 20
130132
steps:
@@ -145,6 +147,7 @@ jobs:
145147
146148
make_sdist:
147149
name: Make SDist
150+
needs: [pre-commit, test-js, test-py]
148151
runs-on: ubuntu-latest
149152
timeout-minutes: 10
150153
steps:
@@ -197,3 +200,44 @@ jobs:
197200
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1
198201
with:
199202
ignore_links: "../api/*.* ./api/* .*/images/[\\w-]+.png https://docs.github.com/en/.* https://mybinder.org/v2/gh/jupyterlab/jupyter_collaboration/.*"
203+
204+
ui_tests:
205+
runs-on: ubuntu-latest
206+
needs: [pre-commit, test-js]
207+
timeout-minutes: 30
208+
env:
209+
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/pw-browsers
210+
steps:
211+
- uses: actions/checkout@v3
212+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
213+
- name: Install dependencies
214+
run: |
215+
pip install jupyterlab .
216+
- name: Install playwright
217+
env:
218+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
219+
run: |
220+
jlpm install
221+
working-directory: ui-tests
222+
- name: Set up browser cache
223+
uses: actions/cache@v3
224+
with:
225+
path: |
226+
${{ github.workspace }}/pw-browsers
227+
key: ${{ runner.os }}-${{ hashFiles('ui-tests/yarn.lock') }}
228+
- name: Install browser
229+
run: jlpm playwright install chromium
230+
working-directory: ui-tests
231+
232+
- name: run tests
233+
working-directory: ui-tests
234+
run: |
235+
jlpm test
236+
- name: Upload Playwright Test report
237+
if: always()
238+
uses: actions/upload-artifact@v3
239+
with:
240+
name: jupyter-collaboration-playwright-report
241+
path: |
242+
ui-tests/test-results
243+
ui-tests/playwright-report

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ dmypy.json
126126
docs/source/changelog.md
127127

128128
.pnp.*
129-
.yarn/*
129+
.yarn/
130130
!.yarn/patches
131131
!.yarn/plugins
132132
!.yarn/releases

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
**/tsconfig.test.json
77
**/*.d.ts
88
**/test
9-
**/ui-tests
109

1110
docs
1211
tests

jupyter_collaboration/rooms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ async def _on_content_change(self, event: str, args: dict[str, Any]) -> None:
187187
event (str): Type of change.
188188
args (dict): A dictionary with format, type, last_modified.
189189
"""
190-
if event == "metadata" and self._last_modified < args["last_modified"]:
190+
if event == "metadata" and (
191+
self._last_modified is None or self._last_modified < args["last_modified"]
192+
):
191193
self.log.info("Out-of-band changes. Overwriting the content in room %s", self._room_id)
192194
self._emit(LogLevel.INFO, "overwrite", "Out-of-band changes. Overwriting the room.")
193195

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
"name": "Jupyter Development Team",
2222
"email": "[email protected]"
2323
},
24-
"workspaces": {
25-
"packages": [
26-
"packages/*"
27-
]
28-
},
24+
"workspaces": [
25+
"packages/*"
26+
],
2927
"scripts": {
3028
"build": "lerna run build",
3129
"build:prod": "lerna run build:prod",

packages/collaboration-extension/src/collaboration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
JupyterFrontEnd,
1010
JupyterFrontEndPlugin
1111
} from '@jupyterlab/application';
12-
import { DOMUtils, IToolbarWidgetRegistry } from '@jupyterlab/apputils';
12+
import { IToolbarWidgetRegistry } from '@jupyterlab/apputils';
1313
import {
1414
EditorExtensionRegistry,
1515
IEditorExtensionRegistry
@@ -139,7 +139,7 @@ export const rtcPanelPlugin: JupyterFrontEndPlugin<void> = {
139139
const userPanel = new SidePanel({
140140
alignment: 'justify'
141141
});
142-
userPanel.id = DOMUtils.createDomID();
142+
userPanel.id = 'jp-collaboration-panel';
143143
userPanel.title.icon = usersIcon;
144144
userPanel.title.caption = trans.__('Collaboration');
145145
userPanel.addClass('jp-RTCPanel');

packages/collaboration/src/collaboratorspanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class CollaboratorsPanel extends Panel {
7575
state.forEach((value: ICollaboratorAwareness, key: any) => {
7676
if (
7777
this._currentUser.isReady &&
78-
value.user.name !== this._currentUser.identity!.name
78+
value.user.username !== this._currentUser.identity!.username
7979
) {
8080
collaborators.push(value);
8181
}

ui-tests/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Integration Testing
2+
3+
This folder contains the integration tests of *jupyter_collaboration*.
4+
5+
They are defined using [Playwright](https://playwright.dev/docs/intro) test runner
6+
and [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) helper.
7+
8+
The Playwright configuration is defined in [playwright.config.js](./playwright.config.js).
9+
10+
The JupyterLab server configuration to use for the integration test is defined
11+
in [jupyter_server_test_config.py](./jupyter_server_test_config.py).
12+
13+
The default configuration will produce video for failing tests and an HTML report.
14+
15+
## Run the tests
16+
17+
> All commands are assumed to be executed from the root directory
18+
19+
To run the tests, you need to:
20+
21+
1. Compile the project:
22+
23+
```sh
24+
jlpm install
25+
jlpm build:prod
26+
```
27+
28+
2. Install test dependencies (needed only once):
29+
30+
```sh
31+
cd ./ui-tests
32+
jlpm install
33+
jlpm playwright install
34+
cd ..
35+
```
36+
37+
3. Execute the [Playwright](https://playwright.dev/docs/intro) tests:
38+
39+
```sh
40+
cd ./ui-tests
41+
jlpm playwright test
42+
```
43+
44+
Test results will be shown in the terminal. In case of any test failures, the test report
45+
will be opened in your browser at the end of the tests execution; see
46+
[Playwright documentation](https://playwright.dev/docs/test-reporters#html-reporter)
47+
for configuring that behavior.
48+
49+
## Update the tests snapshots
50+
51+
> All commands are assumed to be executed from the root directory
52+
53+
If you are comparing snapshots to validate your tests, you may need to update
54+
the reference snapshots stored in the repository. To do that, you need to:
55+
56+
1. Compile the project:
57+
58+
```sh
59+
jlpm install
60+
jlpm build:prod
61+
```
62+
63+
2. Install test dependencies (needed only once):
64+
65+
```sh
66+
cd ./ui-tests
67+
jlpm install
68+
jlpm playwright install
69+
cd ..
70+
```
71+
72+
3. Execute the [Playwright](https://playwright.dev/docs/intro) command:
73+
74+
```sh
75+
cd ./ui-tests
76+
jlpm playwright test -u
77+
```
78+
79+
## Create tests
80+
81+
> All commands are assumed to be executed from the root directory
82+
83+
To create tests, the easiest way is to use the code generator tool of playwright:
84+
85+
1. Compile the extension:
86+
87+
```sh
88+
jlpm install
89+
jlpm build:prod
90+
```
91+
92+
> Check the extension is installed in JupyterLab.
93+
94+
2. Install test dependencies (needed only once):
95+
96+
```sh
97+
cd ./ui-tests
98+
jlpm install
99+
jlpm playwright install
100+
cd ..
101+
```
102+
103+
3. Execute the [Playwright code generator](https://playwright.dev/docs/codegen):
104+
105+
```sh
106+
cd ./ui-tests
107+
jlpm playwright codegen localhost:8888
108+
```
109+
110+
## Debug tests
111+
112+
> All commands are assumed to be executed from the root directory
113+
114+
To debug tests, a good way is to use the inspector tool of playwright:
115+
116+
1. Compile the extension:
117+
118+
```sh
119+
jlpm install
120+
jlpm build:prod
121+
```
122+
123+
> Check the extension is installed in JupyterLab.
124+
125+
2. Install test dependencies (needed only once):
126+
127+
```sh
128+
cd ./ui-tests
129+
jlpm install
130+
jlpm playwright install
131+
cd ..
132+
```
133+
134+
3. Execute the Playwright tests in [debug mode](https://playwright.dev/docs/debug):
135+
136+
```sh
137+
cd ./ui-tests
138+
PWDEBUG=1 jlpm playwright test
139+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
4+
"""Server configuration for integration tests.
5+
6+
!! Never use this configuration in production because it
7+
opens the server to the world and provide access to JupyterLab
8+
JavaScript objects through the global window variable.
9+
"""
10+
from typing import Any
11+
12+
from jupyterlab.galata import configure_jupyter_server
13+
14+
c: Any
15+
configure_jupyter_server(c) # noqa
16+
17+
# Uncomment to set server log level to debug level
18+
# c.ServerApp.log_level = "DEBUG"

ui-tests/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "glue-lab-ui-tests",
3+
"version": "1.0.0",
4+
"description": "JupyterLab glue-lab Integration Tests",
5+
"private": true,
6+
"scripts": {
7+
"start": "jupyter lab --config jupyter_server_test_config.py",
8+
"test": "npx playwright test",
9+
"test:update": "npx playwright test --update-snapshots"
10+
},
11+
"devDependencies": {
12+
"@jupyterlab/galata": "^5.0.0",
13+
"@jupyterlab/services": "^7.0.0",
14+
"@playwright/test": "^1.35.0"
15+
},
16+
"resolutions": {
17+
"@playwright/test": "1.35.0"
18+
}
19+
}

0 commit comments

Comments
 (0)