Skip to content

Commit f1d9a31

Browse files
bollwyvlkrassowski
authored andcommitted
Add Browser Tests (#62)
* merge upstream * restore combine, add ridiculous blanket sleep on windows * actually click on command palette input * add some windows drive handling * make constant for win patch match * also handle failing reads (r, win) * update jest config * linting * wuks the initial click of jump symbol * update some docs with atest info * will update docs for ci
1 parent cb89941 commit f1d9a31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+760
-115
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@ venv.bak/
106106

107107
node_modules
108108
.yarn-packages
109+
110+
atest/output/
111+
junit.xml
112+
coverage/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ envs
2828
**/.ipynb_checkpoints
2929
**/*.egg-info
3030
.yarn-packages
31+
atest
32+
coverage

.travis.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ matrix:
1717
language: shell
1818

1919
before_install:
20-
- python3 -m pip install -r requirements-test.txt
20+
- python3 -m pip install -r requirements-utest.txt
2121
- python3 -m pip freeze
2222
- python3 setup.py sdist
2323
- python3 setup.py bdist_wheel
@@ -30,14 +30,7 @@ script:
3030
- jlpm test
3131
- python3 -m jupyter serverextension list
3232
- python3 -m jupyter serverextension list | grep jupyter_lsp
33-
# don't use setup.py test to ensure testing as-packaged
34-
- python3 -m pytest
35-
--pyargs jupyter_lsp
36-
--cov jupyter_lsp
37-
--cov-report term-missing:skip-covered
38-
-p no:warnings
39-
--flake8
40-
--cov-fail-under=100
33+
- python3 scripts/utest.py
4134

4235
addons:
4336
apt:

atest/00_Smoke.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*** Settings ***
2+
Resource Keywords.robot
3+
4+
*** Test Cases ***
5+
Smoke
6+
Capture Page Screenshot 00-splash.png

atest/01_Editor.robot

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
*** Settings ***
2+
Force Tags ui:editor
3+
Resource Keywords.robot
4+
5+
*** Variables ***
6+
${MENU EDITOR} xpath://div[contains(@class, 'p-Menu-itemLabel')][contains(., "Editor")]
7+
${MENU OPEN WITH} xpath://div[contains(@class, 'p-Menu-itemLabel')][contains(text(), "Open With")]
8+
${MENU JUMP} xpath://div[contains(@class, 'p-Menu-itemLabel')][contains(text(), "Jump to definition")]
9+
${CM CURSOR} css:.CodeMirror-cursor
10+
${CM CURSORS} css:.CodeMirror-cursors:not([style='visibility: hidden'])
11+
12+
*** Test Cases ***
13+
Bash
14+
Editor Shows Features for Language Bash example.sh Diagnostics=Failed to parse expression Jump to Definition=fib
15+
16+
CSS
17+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable-2')][contains(text(), '--some-var')])[last()]
18+
Editor Shows Features for Language CSS example.css Diagnostics=Do not use empty rulesets Jump to Definition=${def}
19+
20+
Docker
21+
${def} = Set Variable xpath://span[contains(@class, 'cm-string')][contains(text(), 'PLANET')]
22+
Editor Shows Features for Language Docker Dockerfile Diagnostics=Instruction has no arguments Jump to Definition=${def}
23+
24+
JS
25+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'fib')])[last()]
26+
Editor Shows Features for Language JS example.js Diagnostics=Expression expected Jump to Definition=${def}
27+
28+
JSON
29+
Editor Shows Features for Language JSON example.json Diagnostics=Duplicate object key
30+
31+
JSX
32+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'hello')])[last()]
33+
Editor Shows Features for Language JSX example.jsx Diagnostics=Expression expected Jump to Definition=${def}
34+
35+
Less
36+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable-2')][contains(text(), '@width')])[last()]
37+
Editor Shows Features for Language Less example.less Diagnostics=Do not use empty rulesets Jump to Definition=${def}
38+
39+
Python
40+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'fib')])[last()]
41+
Editor Shows Features for Language Python example.py Diagnostics=multiple spaces after keyword Jump to Definition=${def}
42+
43+
R
44+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'fib')])[last()]
45+
Editor Shows Features for Language R example.R Diagnostics=Put spaces around all infix operators Jump to Definition=${def}
46+
47+
SCSS
48+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable-2')][contains(text(), 'primary-color')])[last()]
49+
Editor Shows Features for Language SCSS example.scss Diagnostics=Do not use empty rulesets Jump to Definition=${def}
50+
51+
TSX
52+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-tag')][contains(text(), 'HelloWorld')])[last()]
53+
Editor Shows Features for Language TSX example.tsx Diagnostics=Cannot find module 'react' Jump to Definition=${def}
54+
55+
TypeScript
56+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'inc')])[last()]
57+
Editor Shows Features for Language TypeScript example.ts Diagnostics=The left-hand side of an arithmetic Jump to Definition=${def}
58+
59+
YAML
60+
Editor Shows Features for Language YAML example.yaml Diagnostics=duplicate key
61+
62+
*** Keywords ***
63+
Editor Shows Features for Language
64+
[Arguments] ${Language} ${file} &{features}
65+
Set Tags language:${Language.lower()}
66+
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}editor${/}${Language.lower()}
67+
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
68+
Reset Application State
69+
Open ${file} in Editor
70+
FOR ${f} IN @{features}
71+
Run Keyword If "${f}" == "Diagnostics" Editor Should Show Diagnostics ${features["${f}"]}
72+
... ELSE IF "${f}" == "Jump to Definition" Editor Should Jump To Definition ${features["${f}"]}
73+
END
74+
[Teardown] Remove File ${OUTPUT DIR}${/}home${/}${file}
75+
76+
Open ${file} in Editor
77+
Open Context Menu css:.jp-DirListing-item[title="${file}"]
78+
Mouse Over ${MENU OPEN WITH}
79+
Wait Until Page Contains Element ${MENU EDITOR}
80+
Mouse Over ${MENU EDITOR}
81+
Click Element ${MENU EDITOR}
82+
83+
Editor Should Show Diagnostics
84+
[Arguments] ${diagnostic}
85+
Set Tags feature:diagnostics
86+
Wait Until Page Contains Element css:.cm-lsp-diagnostic[title*="${diagnostic}"] timeout=20s
87+
Capture Page Screenshot diagnostics.png
88+
89+
Editor Should Jump To Definition
90+
[Arguments] ${symbol}
91+
Set Tags feature:jump-to-definition
92+
${sel} = Set Variable If "${symbol}".startswith(("xpath", "css")) ${symbol} xpath:(//span[@role="presentation"][contains(., "${symbol}")])[last()]
93+
Mouse Over ${sel}
94+
Run Keyword If "${OS}" == "Windows" Sleep 10s
95+
Wait Until Keyword Succeeds 10 x 0.1 s Click Element ${sel}
96+
Wait Until Keyword Succeeds 10 x 0.1 s Open Context Menu ${sel}
97+
${cursor} = Measure Cursor Position
98+
Capture Page Screenshot jump-to-definition-0.png
99+
Mouse Over ${MENU JUMP}
100+
Capture Page Screenshot jump-to-definition-1.png
101+
Click Element ${MENU JUMP}
102+
Wait Until Keyword Succeeds 10 x 1 s Cursor Should Jump ${cursor}
103+
Capture Page Screenshot jump-to-definition-2.png
104+
105+
Cursor Should Jump
106+
[Arguments] ${original}
107+
${current} = Measure Cursor Position
108+
Should Not Be Equal ${original} ${current}
109+
110+
Measure Cursor Position
111+
Wait Until Page Contains Element ${CM CURSORS}
112+
${position} = Wait Until Keyword Succeeds 20 x 0.05s Get Vertical Position ${CM CURSOR}
113+
[Return] ${position}

atest/Keywords.robot

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
*** Settings ***
2+
Resource Variables.robot
3+
Library SeleniumLibrary
4+
Library OperatingSystem
5+
Library Process
6+
Library String
7+
8+
9+
*** Keywords ***
10+
Setup Server and Browser
11+
${accel} = Evaluate "COMMAND" if "${OS}" == "Darwin" else "CTRL"
12+
Set Global Variable ${ACCEL} ${accel}
13+
${token} = Generate Random String
14+
Set Global Variable ${TOKEN} ${token}
15+
${home} = Set Variable ${OUTPUT DIR}${/}home
16+
${root} = Normalize Path ${OUTPUT DIR}${/}..${/}..${/}..
17+
Create Directory ${home}
18+
${WORKSPACES DIR} = Set Variable ${OUTPUT DIR}${/}workspaces
19+
Initialize User Settings
20+
${app args} = Set Variable --no-browser --debug --NotebookApp.base_url\='${BASE}' --port\=${PORT} --NotebookApp.token\='${token}'
21+
${path args} = Set Variable --LabApp.user_settings_dir='${SETTINGS DIR.replace('\\', '\\\\')}' --LabApp.workspaces_dir\='${WORKSPACES DIR.replace('\\', '\\\\')}'
22+
${ext args} = Set Variable --LanguageServerManager.extra_node_roots\="['${root.replace('\\', '\\\\')}']"
23+
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots
24+
${server} = Start Process jupyter-lab ${app args} ${path args} ${ext args}
25+
... shell=yes
26+
... env:HOME=${home}
27+
... cwd=${home}
28+
... stdout=${OUTPUT DIR}${/}lab.log
29+
... stderr=STDOUT
30+
Set Global Variable ${SERVER} ${server}
31+
Open JupyterLab
32+
33+
Initialize User Settings
34+
Set Suite Variable ${SETTINGS DIR} ${OUTPUT DIR}${/}user-settings children=${True}
35+
Create File ${SETTINGS DIR}${/}@jupyterlab${/}codemirror-extension${/}commands.jupyterlab-settings {"styleActiveLine": true}
36+
37+
Tear Down Everything
38+
Close All Browsers
39+
Evaluate __import__("urllib.request").request.urlopen("${URL}api/shutdown?token=${TOKEN}", data=[])
40+
Wait For Process ${SERVER} timeout=30s
41+
Terminate All Processes
42+
Terminate All Processes kill=${True}
43+
44+
Wait For Splash
45+
Wait Until Page Contains Element ${SPLASH} timeout=180s
46+
Wait Until Page Does Not Contain Element ${SPLASH}
47+
48+
Open JupyterLab
49+
Set Environment Variable MOZ_HEADLESS ${HEADLESS}
50+
${firefox} = Which firefox
51+
${geckodriver} = Which geckodriver
52+
Create WebDriver Firefox executable_path=${geckodriver} firefox_binary=${firefox}
53+
Go To ${URL}lab?token=${TOKEN}
54+
Set Window Size 1024 768
55+
Wait For Splash
56+
Execute Javascript window.onbeforeunload \= function (){}
57+
58+
Close JupyterLab
59+
Close All Browsers
60+
61+
Reset Application State
62+
Lab Command Reset Application State
63+
Wait For Splash
64+
65+
Lab Command
66+
[Arguments] ${cmd}
67+
Press Keys id:main ${ACCEL}+SHIFT+c
68+
${cmd input} = Set Variable css:.p-CommandPalette-input
69+
Wait Until Page Contains Element ${cmd input}
70+
Click Element ${cmd input}
71+
Input Text ${cmd input} ${cmd}
72+
${cmd item} = Set Variable css:.p-CommandPalette-item.p-mod-active
73+
Wait Until Page Contains Element ${cmd item}
74+
Click Element ${cmd item}
75+
76+
Which
77+
[Arguments] ${cmd}
78+
${path} = Evaluate __import__("shutil").which("${cmd}")
79+
[Return] ${path}

atest/Variables.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*** Variables ***
2+
${PORT} 18888
3+
${SPLASH} id:jupyterlab-splash
4+
${BASE} /@est/
5+
${URL} http://localhost:${PORT}${BASE}
6+
${HEADLESS} 1

atest/__init__.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*** Settings ***
2+
Suite Setup Setup Server and Browser
3+
Suite Teardown Tear Down Everything
4+
Test Setup Reset Application State
5+
Force Tags os:${OS.lower()} py:${PY}
6+
Resource Keywords.robot

atest/examples/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM empty
2+
RUN
3+
ARG PLANET="earth"
4+
ENV MY_PLANET="$PLANET"
5+
RUN echo Hello $MY_PLANET

atest/examples/example.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fib=function(n,x=c(0,1)) {
2+
if (abs(n)>1) for (i in seq(abs(n)-1)) x=c(x[2],sum(x))
3+
if (n<0) return(x[2]*(-1)^(abs(n)-1)) else if (n) return(x[2]) else return(0)
4+
}
5+
6+
sapply(seq(-31,31), fib)

0 commit comments

Comments
 (0)