Skip to content

Commit 098cd89

Browse files
committed
Add UI tests with voila-fps
1 parent cde9849 commit 098cd89

File tree

5 files changed

+69
-31
lines changed

5 files changed

+69
-31
lines changed

.github/workflows/ui-tests.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
run: |
4949
python -m pip install --upgrade pip jupyterlab~=3.0 numpy bqplot matplotlib ipympl==0.8.0 ipyvolume scipy
5050
python -m pip install ".[test]"
51+
python -m pip install fps[uvicorn]
52+
python -m pip install fps_plugins/voila
5153
jlpm
5254
jlpm build
5355
jupyter labextension develop . --overwrite
@@ -59,6 +61,7 @@ jobs:
5961
cd ui-tests
6062
# Mount a volume to overwrite the server configuration
6163
jlpm start 2>&1 > /tmp/jupyterlab_server.log &
64+
jlpm start-fps 2>&1 > /tmp/fps_server.log &
6265
6366
- name: Install browser
6467
run: |
@@ -108,6 +111,8 @@ jobs:
108111
# Save PR number for comment publication
109112
echo "${{ github.event.number }}" > ./benchmark-results/NR
110113
114+
jlpm run test-fps
115+
111116
- name: Upload Playwright Test assets
112117
if: always()
113118
uses: actions/upload-artifact@v2
@@ -135,5 +140,7 @@ jobs:
135140
- name: Print JupyterLab logs
136141
if: always()
137142
run: |
143+
echo "Voila log:"
138144
cat /tmp/jupyterlab_server.log
139-
145+
echo "Voila-FPS log:"
146+
cat /tmp/fps_server.log

fps_plugins/voila/fps_voila/routes.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def render_template(self, name, **kwargs):
4444

4545
class FPSVoilaHandler(_VoilaHandler):
4646
is_fps = True
47+
request = Config()
4748
fps_arguments = {}
4849
html = []
4950

@@ -134,7 +135,11 @@ async def shutdown_kernel(kernel_id):
134135

135136
@router.get("/notebooks/{path:path}")
136137
async def get_root(path, voila_template: Optional[str] = None, voila_theme: Optional[str] = None):
137-
return StreamingResponse(_get(fps_voila_handler, path))
138+
fps_voila_handler.request.query = request.query_params
139+
fps_voila_handler.request.path = request.url.path
140+
fps_voila_handler.request.host = f"{request.url.hostname}:{request.url.port}"
141+
fps_voila_handler.request.headers = request.headers
142+
return StreamingResponse(_get(fps_voila_handler, path))
138143

139144
@router.get("/")
140145
async def get_root(request: Request, voila_template: Optional[str] = None, voila_theme: Optional[str] = None):
@@ -148,13 +153,21 @@ async def get_root(request: Request, voila_template: Optional[str] = None, voila
148153
fps_voila_tree_handler.request.path = request.url.path
149154
return _get_tree(fps_voila_tree_handler, "/")
150155
else:
156+
fps_voila_handler.request.query = request.query_params
157+
fps_voila_handler.request.path = request.url.path
158+
fps_voila_handler.request.host = f"{request.url.hostname}:{request.url.port}"
159+
fps_voila_handler.request.headers = request.headers
151160
return StreamingResponse(_get(fps_voila_handler, ""))
152161

153162
@router.get("/voila/render/{path:path}")
154163
async def get_path(request: Request, path):
155164
if C.notebook_path:
156165
raise HTTPException(status_code=404, detail="Not found")
157166
else:
167+
fps_voila_handler.request.query = request.query_params
168+
fps_voila_handler.request.path = request.url.path
169+
fps_voila_handler.request.host = f"{request.url.hostname}:{request.url.port}"
170+
fps_voila_handler.request.headers = request.headers
158171
return StreamingResponse(_get(fps_voila_handler, path))
159172

160173
@router.get("/voila/tree{path:path}")

ui-tests/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"private": true,
66
"scripts": {
77
"start": "voila ../notebooks --no-browser",
8+
"start-fps": "voila ../notebooks --no-browser --fps --port=8867",
89
"start:detached": "yarn run start-jlab&",
9-
"test": "playwright test",
10-
"test:debug": "PWDEBUG=1 playwright test",
10+
"test": "playwright test --project voila",
11+
"test-fps": "playwright test --project voila-fps",
12+
"test:debug": "PWDEBUG=1 playwright test --project voila",
1113
"test:report": "http-server ./playwright-report -a localhost -o",
12-
"test:update": "playwright test --update-snapshots"
14+
"test:update": "playwright test --project voila --update-snapshots"
1315
},
1416
"author": "Project Jupyter",
1517
"license": "BSD-3-Clause",

ui-tests/playwright.config.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
const baseConfig = require('@jupyterlab/galata/lib/playwright-config');
22

33
module.exports = {
4-
...baseConfig,
5-
timeout: 240000,
4+
projects: [
5+
{
6+
...baseConfig,
7+
name: 'voila',
8+
timeout: 240000,
9+
use: {
10+
baseURL: 'http://localhost:8866/voila/',
11+
video: 'retain-on-failure'
12+
},
13+
// Try one retry as some tests are flaky
14+
retries: 1
15+
},
16+
{
17+
...baseConfig,
18+
name: 'voila-fps',
19+
timeout: 240000,
20+
use: {
21+
baseURL: 'http://localhost:8867/voila/',
22+
video: 'retain-on-failure'
23+
},
24+
// Try one retry as some tests are flaky
25+
retries: 1
26+
}
27+
],
628
reporter: [
729
[process.env.CI ? 'dot' : 'list'],
830
[
931
'@jupyterlab/galata/lib/benchmarkReporter',
1032
{ outputFile: 'voila-benchmark.json' }
1133
],
1234
['html']
13-
],
14-
use: {
15-
baseURL: 'http://localhost:8866/voila/',
16-
video: 'retain-on-failure'
17-
},
18-
// Try one retry as some tests are flaky
19-
retries: 1
35+
]
2036
};

voila/handler.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ async def _get(self: "_VoilaHandler", path=None):
4444

4545
# Adding request uri to kernel env
4646
kernel_env = os.environ.copy()
47+
kernel_env[ENV_VARIABLE.SCRIPT_NAME] = self.request.path
48+
kernel_env[
49+
ENV_VARIABLE.PATH_INFO
50+
] = '' # would be /foo/bar if voila.ipynb/foo/bar was supported
51+
kernel_env[ENV_VARIABLE.QUERY_STRING] = str(self.request.query)
52+
kernel_env[ENV_VARIABLE.SERVER_SOFTWARE] = 'voila/{}'.format(__version__)
53+
host, port = split_host_and_port(self.request.host.lower())
54+
kernel_env[ENV_VARIABLE.SERVER_PORT] = str(port) if port else ''
55+
kernel_env[ENV_VARIABLE.SERVER_NAME] = host
56+
# Add HTTP Headers as env vars following rfc3875#section-4.1.18
57+
if len(self.voila_configuration.http_header_envs) > 0:
58+
for header_name in self.request.headers:
59+
config_headers_lower = [header.lower() for header in self.voila_configuration.http_header_envs]
60+
# Use case insensitive comparison of header names as per rfc2616#section-4.2
61+
if header_name.lower() in config_headers_lower:
62+
env_name = f'HTTP_{header_name.upper().replace("-", "_")}'
63+
kernel_env[env_name] = self.request.headers.get(header_name)
4764
if not self.is_fps:
48-
kernel_env[ENV_VARIABLE.SCRIPT_NAME] = self.request.path
49-
kernel_env[
50-
ENV_VARIABLE.PATH_INFO
51-
] = '' # would be /foo/bar if voila.ipynb/foo/bar was supported
52-
kernel_env[ENV_VARIABLE.QUERY_STRING] = str(self.request.query)
53-
kernel_env[ENV_VARIABLE.SERVER_SOFTWARE] = 'voila/{}'.format(__version__)
5465
kernel_env[ENV_VARIABLE.SERVER_PROTOCOL] = str(self.request.version)
55-
host, port = split_host_and_port(self.request.host.lower())
56-
kernel_env[ENV_VARIABLE.SERVER_PORT] = str(port) if port else ''
57-
kernel_env[ENV_VARIABLE.SERVER_NAME] = host
58-
# Add HTTP Headers as env vars following rfc3875#section-4.1.18
59-
if len(self.voila_configuration.http_header_envs) > 0:
60-
for header_name in self.request.headers:
61-
config_headers_lower = [header.lower() for header in self.voila_configuration.http_header_envs]
62-
# Use case insensitive comparison of header names as per rfc2616#section-4.2
63-
if header_name.lower() in config_headers_lower:
64-
env_name = f'HTTP_{header_name.upper().replace("-", "_")}'
65-
kernel_env[env_name] = self.request.headers.get(header_name)
6666

6767
template_arg = self.get_argument("voila-template", None)
6868
theme_arg = self.get_argument("voila-theme", None)

0 commit comments

Comments
 (0)