Skip to content

Commit 3ea2e81

Browse files
authored
Merge pull request #20 from martinRenou/ft/add-playwright
Add UI testing
2 parents 2e55eed + 5dbe404 commit 3ea2e81

26 files changed

+1760
-3
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,33 @@ jobs:
3434
run: |
3535
test -d $CONDA_PREFIX/share/jupyter/labextensions/jupyterlab-unfold
3636
test -f $CONDA_PREFIX/share/jupyter/labextensions/jupyterlab-unfold/package.json
37-
37+
3838
jupyter labextension list 2>&1 | grep -ie "jupyterlab-unfold.*OK"
3939
python -m jupyterlab.browser_check
4040
4141
check-manifest -v
42+
43+
- name: UI tests
44+
run: |
45+
docker-compose -f ./docker/docker-compose.yml down || true
46+
docker-compose -f ./docker/docker-compose.yml pull -q || true
47+
docker-compose -f ./docker/docker-compose.yml build
48+
docker-compose -f ./docker/docker-compose.yml run --rm e2e
49+
working-directory: ui-tests
50+
51+
- name: Upload UI Test artifacts
52+
if: always()
53+
uses: actions/upload-artifact@v2
54+
with:
55+
name: ui-test-output
56+
path: |
57+
ui-tests/test-results
58+
59+
- name: Stop containers
60+
if: always()
61+
run: |
62+
# Print jupyterlab logs before removing the containers using the container name set in docker-compose file
63+
docker logs jupyterlab
64+
docker-compose -f ./docker/docker-compose.yml down
65+
working-directory: ui-tests
66+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ dmypy.json
110110

111111
# OSX files
112112
.DS_Store
113+
ui-tests/test-results/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ include schema/jupyterlab-unfold-settings.json
2020
prune **/node_modules
2121
prune lib
2222
prune binder
23+
prune ui-tests
2324

2425
# Patterns to exclude from any directory
2526
global-exclude *~

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
4444
"clean:labextension": "rimraf jupyterlab-unfold/labextension",
4545
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
46-
"eslint": "eslint . --ext .ts,.tsx --fix",
47-
"eslint:check": "eslint . --ext .ts,.tsx",
46+
"eslint": "eslint src --ext .ts,.tsx --fix",
47+
"eslint:check": "eslint src --ext .ts,.tsx",
4848
"install:extension": "jlpm run build",
4949
"watch": "run-p watch:src watch:labextension",
5050
"watch:src": "tsc -w",

ui-tests/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Test
2+
3+
The test will produce a video to help debugging and check what happened.
4+
5+
To execute integration tests, you have two options:
6+
7+
- use docker-compose (cons: needs to know and use docker) - this is a more reliable solution.
8+
- run tests locally (cons: will interact with your JupyterLab user settings)
9+
10+
## Test on docker
11+
12+
1. Compile the extension:
13+
14+
```
15+
jlpm install
16+
```
17+
18+
2. Execute the docker stack in the ui-tests folder:
19+
20+
```
21+
docker-compose -f ./docker/docker-compose.yml build --no-cache
22+
docker-compose -f ./docker/docker-compose.yml run --rm e2e
23+
docker-compose -f ./docker/docker-compose.yml down
24+
```
25+
26+
## Test locally
27+
28+
1. Compile the extension:
29+
30+
```
31+
jlpm install
32+
jlpm run build:prod
33+
```
34+
35+
2. Start JupyterLab _with the extension installed_ without any token or password
36+
37+
```
38+
jupyter lab --ServerApp.token= --ServerApp.password=
39+
```
40+
41+
3. Execute in another console the [Playwright](https://playwright.dev/docs/intro) tests:
42+
43+
```
44+
cd ui-tests
45+
jlpm install
46+
npx playwright install
47+
npx playwright test
48+
```
49+
50+
# Create tests
51+
52+
To create tests, the easiest way is to use the code generator tool of playwright:
53+
54+
1. Compile the extension:
55+
56+
```
57+
jlpm install
58+
jlpm run build:prod
59+
```
60+
61+
2. Start JupyterLab _with the extension installed_ without any token or password:
62+
63+
**Using docker**
64+
65+
```
66+
docker-compose -f ./docker/docker-compose.yml run --rm -p 8888:8888 lab
67+
```
68+
69+
**Using local installation**
70+
71+
```
72+
jupyter lab --ServerApp.token= --ServerApp.password=
73+
```
74+
75+
3. Launch the code generator tool:
76+
77+
```
78+
cd ui-tests
79+
jlpm install
80+
npx playwright install
81+
npx playwright codegen localhost:8888
82+
```
83+
84+
# Debug tests
85+
86+
To debug tests, a good way is to use the inspector tool of playwright:
87+
88+
1. Compile the extension:
89+
90+
```
91+
jlpm install
92+
jlpm run build:prod
93+
```
94+
95+
2. Start JupyterLab _with the extension installed_ without any token or password:
96+
97+
**Using docker**
98+
99+
```
100+
docker-compose -f ./docker/docker-compose.yml run --rm -p 8888:8888 lab
101+
```
102+
103+
**Using local installation**
104+
105+
```
106+
jupyter lab --ServerApp.token= --ServerApp.password=
107+
```
108+
109+
3. Launch the debug tool:
110+
111+
```
112+
cd ui-tests
113+
jlpm install
114+
npx playwright install
115+
PWDEBUG=1 npx playwright test
116+
```

ui-tests/docker/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Use base jupyter image that comes with jupyterlab
2+
FROM jupyter/base-notebook
3+
4+
USER root
5+
6+
# Upgrade JupyterLab
7+
RUN python -m pip install --upgrade jupyterlab
8+
9+
# Copying test structure
10+
COPY ./test_structure/ /home/jovyan/work/
11+
RUN chown -R 1000:1000 /home/jovyan/work/
12+
13+
USER 1000

ui-tests/docker/docker-compose.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: '3.5'
2+
3+
services:
4+
lab:
5+
container_name: jupyterlab
6+
build:
7+
context: .
8+
command: [
9+
'jupyter',
10+
'lab',
11+
# Set working directory as empty directory - no modified time displayed
12+
'--notebook-dir=./work',
13+
'--ServerApp.token=',
14+
'--ServerApp.password=',
15+
'--ServerApp.disable_check_xsrf=True',
16+
'--LabServerApp.extra_labextensions_path=/opt/labextension',
17+
# Workaround bug: https://github.com/ipython/traitlets/issues/668
18+
'--LabServerApp.extra_labextensions_path=/dev/null'
19+
]
20+
networks:
21+
- frontend
22+
ports:
23+
- 8888:8888
24+
volumes:
25+
- ../../jupyterlab-unfold/labextension:/opt/labextension/jupyterlab-unfold
26+
27+
e2e:
28+
# docker must match playwright version in ui-tests/package.json
29+
image: mcr.microsoft.com/playwright:v1.14.0-focal
30+
entrypoint:
31+
[
32+
'/tmp/e2e-tests/prepare.sh',
33+
'jupyterlab:8888',
34+
'--strict',
35+
'--timeout=60',
36+
'--'
37+
]
38+
command: ['npx', 'playwright', 'test']
39+
environment:
40+
# JupyterLab URL
41+
TARGET_URL: http://jupyterlab:8888
42+
# See https://playwright.dev/docs/docker/#run-the-image
43+
ipc: host
44+
networks:
45+
- frontend
46+
depends_on:
47+
- lab
48+
volumes:
49+
- .:/tmp/e2e-tests
50+
- ..:/opt/ui-tests
51+
working_dir: /opt/ui-tests
52+
53+
networks:
54+
frontend:

ui-tests/docker/prepare.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
4+
yarn install --verbose
5+
6+
echo Will run 'wait-for-it' $*
7+
$(dirname $0)/wait-for-it.sh $*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello there
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from time import sleep
2+
3+
sleep(9999999999)

0 commit comments

Comments
 (0)